diff --git a/app/build.gradle b/app/build.gradle
index ae31f07..c4aa488 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
+apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 30
@@ -31,6 +32,12 @@
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
+
+ greendao {
+ schemaVersion 1//数据库版本号
+ targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录
+ daoPackage 'com.casic.dcms.greendao'//设置DaoMaster、DaoSession、Dao包名
+ }
}
dependencies {
@@ -38,7 +45,7 @@
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
@@ -81,4 +88,10 @@
implementation 'com.github.huangyanbin:SmartTable:1.7.1'
implementation 'com.getui:gtsdk:3.1.4.0' //个推SDK
implementation 'com.getui:gtc:3.1.0.0' //个推核心组件
+ //数据库框架
+ implementation 'org.greenrobot:greendao:3.3.0'
+ //沉浸式状态栏。基础依赖包,必须要依赖
+ implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
+ //fragment快速实现
+ implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
}
diff --git a/app/build.gradle b/app/build.gradle
index ae31f07..c4aa488 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
+apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 30
@@ -31,6 +32,12 @@
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
+
+ greendao {
+ schemaVersion 1//数据库版本号
+ targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录
+ daoPackage 'com.casic.dcms.greendao'//设置DaoMaster、DaoSession、Dao包名
+ }
}
dependencies {
@@ -38,7 +45,7 @@
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
@@ -81,4 +88,10 @@
implementation 'com.github.huangyanbin:SmartTable:1.7.1'
implementation 'com.getui:gtsdk:3.1.4.0' //个推SDK
implementation 'com.getui:gtc:3.1.0.0' //个推核心组件
+ //数据库框架
+ implementation 'org.greenrobot:greendao:3.3.0'
+ //沉浸式状态栏。基础依赖包,必须要依赖
+ implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
+ //fragment快速实现
+ implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 35a9c86..d5c56ab 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -57,7 +57,7 @@
+ android:value="${GETUI_APPID}" />
+ android:value="${GETUI_APPID}" />
+ android:value="${GETUI_APPID}" />
+ android:value="${GETUI_APPID}" />
+ android:value="${GETUI_APPID}" />
>, DaoConfig>
+ daoConfigMap) {
+ super(db);
+
+ noticeBeanDaoConfig = daoConfigMap.get(NoticeBeanDao.class).clone();
+ noticeBeanDaoConfig.initIdentityScope(type);
+
+ noticeBeanDao = new NoticeBeanDao(noticeBeanDaoConfig, this);
+
+ registerDao(NoticeBean.class, noticeBeanDao);
+ }
+
+ public void clear() {
+ noticeBeanDaoConfig.clearIdentityScope();
+ }
+
+ public NoticeBeanDao getNoticeBeanDao() {
+ return noticeBeanDao;
+ }
+
+}
diff --git a/app/build.gradle b/app/build.gradle
index ae31f07..c4aa488 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
+apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 30
@@ -31,6 +32,12 @@
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
+
+ greendao {
+ schemaVersion 1//数据库版本号
+ targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录
+ daoPackage 'com.casic.dcms.greendao'//设置DaoMaster、DaoSession、Dao包名
+ }
}
dependencies {
@@ -38,7 +45,7 @@
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
@@ -81,4 +88,10 @@
implementation 'com.github.huangyanbin:SmartTable:1.7.1'
implementation 'com.getui:gtsdk:3.1.4.0' //个推SDK
implementation 'com.getui:gtc:3.1.0.0' //个推核心组件
+ //数据库框架
+ implementation 'org.greenrobot:greendao:3.3.0'
+ //沉浸式状态栏。基础依赖包,必须要依赖
+ implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
+ //fragment快速实现
+ implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 35a9c86..d5c56ab 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -57,7 +57,7 @@
+ android:value="${GETUI_APPID}" />
>, DaoConfig>
+ daoConfigMap) {
+ super(db);
+
+ noticeBeanDaoConfig = daoConfigMap.get(NoticeBeanDao.class).clone();
+ noticeBeanDaoConfig.initIdentityScope(type);
+
+ noticeBeanDao = new NoticeBeanDao(noticeBeanDaoConfig, this);
+
+ registerDao(NoticeBean.class, noticeBeanDao);
+ }
+
+ public void clear() {
+ noticeBeanDaoConfig.clearIdentityScope();
+ }
+
+ public NoticeBeanDao getNoticeBeanDao() {
+ return noticeBeanDao;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
new file mode 100644
index 0000000..259eb85
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
@@ -0,0 +1,185 @@
+package com.casic.dcms.greendao;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteStatement;
+
+import org.greenrobot.greendao.AbstractDao;
+import org.greenrobot.greendao.Property;
+import org.greenrobot.greendao.internal.DaoConfig;
+import org.greenrobot.greendao.database.Database;
+import org.greenrobot.greendao.database.DatabaseStatement;
+
+import com.casic.dcms.bean.NoticeBean;
+
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
+/**
+ * DAO for table "NOTICE_BEAN".
+*/
+public class NoticeBeanDao extends AbstractDao {
+
+ public static final String TABLENAME = "NOTICE_BEAN";
+
+ /**
+ * Properties of entity NoticeBean.
+ * Can be used for QueryBuilder and for referencing column names.
+ */
+ public static class Properties {
+ public final static Property Id = new Property(0, Long.class, "id", true, "_id");
+ public final static Property NoticeTitle = new Property(1, String.class, "noticeTitle", false, "NOTICE_TITLE");
+ public final static Property NoticeDate = new Property(2, String.class, "noticeDate", false, "NOTICE_DATE");
+ public final static Property NoticeContent = new Property(3, String.class, "noticeContent", false, "NOTICE_CONTENT");
+ public final static Property SenderName = new Property(4, String.class, "senderName", false, "SENDER_NAME");
+ public final static Property IsRead = new Property(5, String.class, "isRead", false, "IS_READ");
+ }
+
+
+ public NoticeBeanDao(DaoConfig config) {
+ super(config);
+ }
+
+ public NoticeBeanDao(DaoConfig config, DaoSession daoSession) {
+ super(config, daoSession);
+ }
+
+ /** Creates the underlying database table. */
+ public static void createTable(Database db, boolean ifNotExists) {
+ String constraint = ifNotExists? "IF NOT EXISTS ": "";
+ db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_BEAN\" (" + //
+ "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
+ "\"NOTICE_TITLE\" TEXT," + // 1: noticeTitle
+ "\"NOTICE_DATE\" TEXT," + // 2: noticeDate
+ "\"NOTICE_CONTENT\" TEXT," + // 3: noticeContent
+ "\"SENDER_NAME\" TEXT," + // 4: senderName
+ "\"IS_READ\" TEXT);"); // 5: isRead
+ }
+
+ /** Drops the underlying database table. */
+ public static void dropTable(Database db, boolean ifExists) {
+ String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_BEAN\"";
+ db.execSQL(sql);
+ }
+
+ @Override
+ protected final void bindValues(DatabaseStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ protected final void bindValues(SQLiteStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ public Long readKey(Cursor cursor, int offset) {
+ return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
+ }
+
+ @Override
+ public NoticeBean readEntity(Cursor cursor, int offset) {
+ NoticeBean entity = new NoticeBean( //
+ cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
+ cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // noticeTitle
+ cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noticeDate
+ cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // noticeContent
+ cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // senderName
+ cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // isRead
+ );
+ return entity;
+ }
+
+ @Override
+ public void readEntity(Cursor cursor, NoticeBean entity, int offset) {
+ entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
+ entity.setNoticeTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
+ entity.setNoticeDate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
+ entity.setNoticeContent(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
+ entity.setSenderName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
+ entity.setIsRead(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
+ }
+
+ @Override
+ protected final Long updateKeyAfterInsert(NoticeBean entity, long rowId) {
+ entity.setId(rowId);
+ return rowId;
+ }
+
+ @Override
+ public Long getKey(NoticeBean entity) {
+ if(entity != null) {
+ return entity.getId();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean hasKey(NoticeBean entity) {
+ return entity.getId() != null;
+ }
+
+ @Override
+ protected final boolean isEntityUpdateable() {
+ return true;
+ }
+
+}
diff --git a/app/build.gradle b/app/build.gradle
index ae31f07..c4aa488 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
+apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 30
@@ -31,6 +32,12 @@
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
+
+ greendao {
+ schemaVersion 1//数据库版本号
+ targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录
+ daoPackage 'com.casic.dcms.greendao'//设置DaoMaster、DaoSession、Dao包名
+ }
}
dependencies {
@@ -38,7 +45,7 @@
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
@@ -81,4 +88,10 @@
implementation 'com.github.huangyanbin:SmartTable:1.7.1'
implementation 'com.getui:gtsdk:3.1.4.0' //个推SDK
implementation 'com.getui:gtc:3.1.0.0' //个推核心组件
+ //数据库框架
+ implementation 'org.greenrobot:greendao:3.3.0'
+ //沉浸式状态栏。基础依赖包,必须要依赖
+ implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
+ //fragment快速实现
+ implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 35a9c86..d5c56ab 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -57,7 +57,7 @@
+ android:value="${GETUI_APPID}" />
>, DaoConfig>
+ daoConfigMap) {
+ super(db);
+
+ noticeBeanDaoConfig = daoConfigMap.get(NoticeBeanDao.class).clone();
+ noticeBeanDaoConfig.initIdentityScope(type);
+
+ noticeBeanDao = new NoticeBeanDao(noticeBeanDaoConfig, this);
+
+ registerDao(NoticeBean.class, noticeBeanDao);
+ }
+
+ public void clear() {
+ noticeBeanDaoConfig.clearIdentityScope();
+ }
+
+ public NoticeBeanDao getNoticeBeanDao() {
+ return noticeBeanDao;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
new file mode 100644
index 0000000..259eb85
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
@@ -0,0 +1,185 @@
+package com.casic.dcms.greendao;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteStatement;
+
+import org.greenrobot.greendao.AbstractDao;
+import org.greenrobot.greendao.Property;
+import org.greenrobot.greendao.internal.DaoConfig;
+import org.greenrobot.greendao.database.Database;
+import org.greenrobot.greendao.database.DatabaseStatement;
+
+import com.casic.dcms.bean.NoticeBean;
+
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
+/**
+ * DAO for table "NOTICE_BEAN".
+*/
+public class NoticeBeanDao extends AbstractDao {
+
+ public static final String TABLENAME = "NOTICE_BEAN";
+
+ /**
+ * Properties of entity NoticeBean.
+ * Can be used for QueryBuilder and for referencing column names.
+ */
+ public static class Properties {
+ public final static Property Id = new Property(0, Long.class, "id", true, "_id");
+ public final static Property NoticeTitle = new Property(1, String.class, "noticeTitle", false, "NOTICE_TITLE");
+ public final static Property NoticeDate = new Property(2, String.class, "noticeDate", false, "NOTICE_DATE");
+ public final static Property NoticeContent = new Property(3, String.class, "noticeContent", false, "NOTICE_CONTENT");
+ public final static Property SenderName = new Property(4, String.class, "senderName", false, "SENDER_NAME");
+ public final static Property IsRead = new Property(5, String.class, "isRead", false, "IS_READ");
+ }
+
+
+ public NoticeBeanDao(DaoConfig config) {
+ super(config);
+ }
+
+ public NoticeBeanDao(DaoConfig config, DaoSession daoSession) {
+ super(config, daoSession);
+ }
+
+ /** Creates the underlying database table. */
+ public static void createTable(Database db, boolean ifNotExists) {
+ String constraint = ifNotExists? "IF NOT EXISTS ": "";
+ db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_BEAN\" (" + //
+ "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
+ "\"NOTICE_TITLE\" TEXT," + // 1: noticeTitle
+ "\"NOTICE_DATE\" TEXT," + // 2: noticeDate
+ "\"NOTICE_CONTENT\" TEXT," + // 3: noticeContent
+ "\"SENDER_NAME\" TEXT," + // 4: senderName
+ "\"IS_READ\" TEXT);"); // 5: isRead
+ }
+
+ /** Drops the underlying database table. */
+ public static void dropTable(Database db, boolean ifExists) {
+ String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_BEAN\"";
+ db.execSQL(sql);
+ }
+
+ @Override
+ protected final void bindValues(DatabaseStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ protected final void bindValues(SQLiteStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ public Long readKey(Cursor cursor, int offset) {
+ return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
+ }
+
+ @Override
+ public NoticeBean readEntity(Cursor cursor, int offset) {
+ NoticeBean entity = new NoticeBean( //
+ cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
+ cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // noticeTitle
+ cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noticeDate
+ cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // noticeContent
+ cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // senderName
+ cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // isRead
+ );
+ return entity;
+ }
+
+ @Override
+ public void readEntity(Cursor cursor, NoticeBean entity, int offset) {
+ entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
+ entity.setNoticeTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
+ entity.setNoticeDate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
+ entity.setNoticeContent(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
+ entity.setSenderName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
+ entity.setIsRead(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
+ }
+
+ @Override
+ protected final Long updateKeyAfterInsert(NoticeBean entity, long rowId) {
+ entity.setId(rowId);
+ return rowId;
+ }
+
+ @Override
+ public Long getKey(NoticeBean entity) {
+ if(entity != null) {
+ return entity.getId();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean hasKey(NoticeBean entity) {
+ return entity.getId() != null;
+ }
+
+ @Override
+ protected final boolean isEntityUpdateable() {
+ return true;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
index 4ff8b3c..10c9d85 100644
--- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
+++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
@@ -2,6 +2,7 @@
import android.content.Context;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.bean.NoticeBean;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -57,7 +58,11 @@
noticeBean.setSenderName("管理员");
noticeBean.setNoticeDate(TimeOrDateUtil.timestampToDate(System.currentTimeMillis()));
noticeBean.setNoticeContent(msg.getContent());
+ noticeBean.setIsRead("1");
+ //存本地一份
+ BaseApplication.getDaoSession().insert(noticeBean);
+ //发送消息更新界面
BroadcastManager.getInstance(context).sendBroadcast(Constant.NOTICE_MSG, new Gson().toJson(noticeBean));
}
diff --git a/app/build.gradle b/app/build.gradle
index ae31f07..c4aa488 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
+apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 30
@@ -31,6 +32,12 @@
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
+
+ greendao {
+ schemaVersion 1//数据库版本号
+ targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录
+ daoPackage 'com.casic.dcms.greendao'//设置DaoMaster、DaoSession、Dao包名
+ }
}
dependencies {
@@ -38,7 +45,7 @@
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
@@ -81,4 +88,10 @@
implementation 'com.github.huangyanbin:SmartTable:1.7.1'
implementation 'com.getui:gtsdk:3.1.4.0' //个推SDK
implementation 'com.getui:gtc:3.1.0.0' //个推核心组件
+ //数据库框架
+ implementation 'org.greenrobot:greendao:3.3.0'
+ //沉浸式状态栏。基础依赖包,必须要依赖
+ implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
+ //fragment快速实现
+ implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 35a9c86..d5c56ab 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -57,7 +57,7 @@
+ android:value="${GETUI_APPID}" />
>, DaoConfig>
+ daoConfigMap) {
+ super(db);
+
+ noticeBeanDaoConfig = daoConfigMap.get(NoticeBeanDao.class).clone();
+ noticeBeanDaoConfig.initIdentityScope(type);
+
+ noticeBeanDao = new NoticeBeanDao(noticeBeanDaoConfig, this);
+
+ registerDao(NoticeBean.class, noticeBeanDao);
+ }
+
+ public void clear() {
+ noticeBeanDaoConfig.clearIdentityScope();
+ }
+
+ public NoticeBeanDao getNoticeBeanDao() {
+ return noticeBeanDao;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
new file mode 100644
index 0000000..259eb85
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
@@ -0,0 +1,185 @@
+package com.casic.dcms.greendao;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteStatement;
+
+import org.greenrobot.greendao.AbstractDao;
+import org.greenrobot.greendao.Property;
+import org.greenrobot.greendao.internal.DaoConfig;
+import org.greenrobot.greendao.database.Database;
+import org.greenrobot.greendao.database.DatabaseStatement;
+
+import com.casic.dcms.bean.NoticeBean;
+
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
+/**
+ * DAO for table "NOTICE_BEAN".
+*/
+public class NoticeBeanDao extends AbstractDao {
+
+ public static final String TABLENAME = "NOTICE_BEAN";
+
+ /**
+ * Properties of entity NoticeBean.
+ * Can be used for QueryBuilder and for referencing column names.
+ */
+ public static class Properties {
+ public final static Property Id = new Property(0, Long.class, "id", true, "_id");
+ public final static Property NoticeTitle = new Property(1, String.class, "noticeTitle", false, "NOTICE_TITLE");
+ public final static Property NoticeDate = new Property(2, String.class, "noticeDate", false, "NOTICE_DATE");
+ public final static Property NoticeContent = new Property(3, String.class, "noticeContent", false, "NOTICE_CONTENT");
+ public final static Property SenderName = new Property(4, String.class, "senderName", false, "SENDER_NAME");
+ public final static Property IsRead = new Property(5, String.class, "isRead", false, "IS_READ");
+ }
+
+
+ public NoticeBeanDao(DaoConfig config) {
+ super(config);
+ }
+
+ public NoticeBeanDao(DaoConfig config, DaoSession daoSession) {
+ super(config, daoSession);
+ }
+
+ /** Creates the underlying database table. */
+ public static void createTable(Database db, boolean ifNotExists) {
+ String constraint = ifNotExists? "IF NOT EXISTS ": "";
+ db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_BEAN\" (" + //
+ "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
+ "\"NOTICE_TITLE\" TEXT," + // 1: noticeTitle
+ "\"NOTICE_DATE\" TEXT," + // 2: noticeDate
+ "\"NOTICE_CONTENT\" TEXT," + // 3: noticeContent
+ "\"SENDER_NAME\" TEXT," + // 4: senderName
+ "\"IS_READ\" TEXT);"); // 5: isRead
+ }
+
+ /** Drops the underlying database table. */
+ public static void dropTable(Database db, boolean ifExists) {
+ String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_BEAN\"";
+ db.execSQL(sql);
+ }
+
+ @Override
+ protected final void bindValues(DatabaseStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ protected final void bindValues(SQLiteStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ public Long readKey(Cursor cursor, int offset) {
+ return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
+ }
+
+ @Override
+ public NoticeBean readEntity(Cursor cursor, int offset) {
+ NoticeBean entity = new NoticeBean( //
+ cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
+ cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // noticeTitle
+ cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noticeDate
+ cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // noticeContent
+ cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // senderName
+ cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // isRead
+ );
+ return entity;
+ }
+
+ @Override
+ public void readEntity(Cursor cursor, NoticeBean entity, int offset) {
+ entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
+ entity.setNoticeTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
+ entity.setNoticeDate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
+ entity.setNoticeContent(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
+ entity.setSenderName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
+ entity.setIsRead(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
+ }
+
+ @Override
+ protected final Long updateKeyAfterInsert(NoticeBean entity, long rowId) {
+ entity.setId(rowId);
+ return rowId;
+ }
+
+ @Override
+ public Long getKey(NoticeBean entity) {
+ if(entity != null) {
+ return entity.getId();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean hasKey(NoticeBean entity) {
+ return entity.getId() != null;
+ }
+
+ @Override
+ protected final boolean isEntityUpdateable() {
+ return true;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
index 4ff8b3c..10c9d85 100644
--- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
+++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
@@ -2,6 +2,7 @@
import android.content.Context;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.bean.NoticeBean;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -57,7 +58,11 @@
noticeBean.setSenderName("管理员");
noticeBean.setNoticeDate(TimeOrDateUtil.timestampToDate(System.currentTimeMillis()));
noticeBean.setNoticeContent(msg.getContent());
+ noticeBean.setIsRead("1");
+ //存本地一份
+ BaseApplication.getDaoSession().insert(noticeBean);
+ //发送消息更新界面
BroadcastManager.getInstance(context).sendBroadcast(Constant.NOTICE_MSG, new Gson().toJson(noticeBean));
}
diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
index 1de7445..5f857bc 100644
--- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java
+++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
@@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
@@ -19,9 +20,10 @@
import com.casic.dcms.ui.fragment.PhonePageFragment;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
+import com.casic.dcms.utils.StatusBarColorUtil;
import com.casic.dcms.widgets.NoScrollViewPager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
-import com.qmuiteam.qmui.widget.QMUITopBarLayout;
+import com.gyf.immersionbar.ImmersionBar;
import java.util.ArrayList;
import java.util.List;
@@ -31,13 +33,12 @@
public class MainActivity extends DoubleClickExitActivity {
private static final String TAG = "MainActivity";
- @BindView(R.id.mainTopLayout)
- QMUITopBarLayout mainTopLayout;
+ @BindView(R.id.pageTitleView)
+ TextView pageTitleView;
@BindView(R.id.mainViewPager)
NoScrollViewPager mainViewPager;
@BindView(R.id.bottomNavigation)
BottomNavigationView bottomNavigation;
- private Context context = this;
private MenuItem menuItem;
private List pageList;
private BroadcastManager broadcastManager;
@@ -49,8 +50,9 @@
@Override
protected void setupTopBarLayout() {
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
- mainTopLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor));
+ StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor));
+ ImmersionBar.with(this).statusBarDarkFont(false).init();
+ pageTitleView.setText("首页");
}
@Override
@@ -88,19 +90,19 @@
switch (item.getItemId()) {
case R.id.navigation_home:
mainViewPager.setCurrentItem(0);
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("首页");
break;
case R.id.navigation_phone:
mainViewPager.setCurrentItem(1);
- mainTopLayout.setTitle("通讯录").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("通讯录");
break;
case R.id.navigation_dashboard:
mainViewPager.setCurrentItem(2);
- mainTopLayout.setTitle("消息").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("消息");
break;
case R.id.navigation_mine:
mainViewPager.setCurrentItem(3);
- mainTopLayout.setTitle("我的").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("我的");
break;
default:
break;
diff --git a/app/build.gradle b/app/build.gradle
index ae31f07..c4aa488 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
+apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 30
@@ -31,6 +32,12 @@
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
+
+ greendao {
+ schemaVersion 1//数据库版本号
+ targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录
+ daoPackage 'com.casic.dcms.greendao'//设置DaoMaster、DaoSession、Dao包名
+ }
}
dependencies {
@@ -38,7 +45,7 @@
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
@@ -81,4 +88,10 @@
implementation 'com.github.huangyanbin:SmartTable:1.7.1'
implementation 'com.getui:gtsdk:3.1.4.0' //个推SDK
implementation 'com.getui:gtc:3.1.0.0' //个推核心组件
+ //数据库框架
+ implementation 'org.greenrobot:greendao:3.3.0'
+ //沉浸式状态栏。基础依赖包,必须要依赖
+ implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
+ //fragment快速实现
+ implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 35a9c86..d5c56ab 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -57,7 +57,7 @@
+ android:value="${GETUI_APPID}" />
>, DaoConfig>
+ daoConfigMap) {
+ super(db);
+
+ noticeBeanDaoConfig = daoConfigMap.get(NoticeBeanDao.class).clone();
+ noticeBeanDaoConfig.initIdentityScope(type);
+
+ noticeBeanDao = new NoticeBeanDao(noticeBeanDaoConfig, this);
+
+ registerDao(NoticeBean.class, noticeBeanDao);
+ }
+
+ public void clear() {
+ noticeBeanDaoConfig.clearIdentityScope();
+ }
+
+ public NoticeBeanDao getNoticeBeanDao() {
+ return noticeBeanDao;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
new file mode 100644
index 0000000..259eb85
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
@@ -0,0 +1,185 @@
+package com.casic.dcms.greendao;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteStatement;
+
+import org.greenrobot.greendao.AbstractDao;
+import org.greenrobot.greendao.Property;
+import org.greenrobot.greendao.internal.DaoConfig;
+import org.greenrobot.greendao.database.Database;
+import org.greenrobot.greendao.database.DatabaseStatement;
+
+import com.casic.dcms.bean.NoticeBean;
+
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
+/**
+ * DAO for table "NOTICE_BEAN".
+*/
+public class NoticeBeanDao extends AbstractDao {
+
+ public static final String TABLENAME = "NOTICE_BEAN";
+
+ /**
+ * Properties of entity NoticeBean.
+ * Can be used for QueryBuilder and for referencing column names.
+ */
+ public static class Properties {
+ public final static Property Id = new Property(0, Long.class, "id", true, "_id");
+ public final static Property NoticeTitle = new Property(1, String.class, "noticeTitle", false, "NOTICE_TITLE");
+ public final static Property NoticeDate = new Property(2, String.class, "noticeDate", false, "NOTICE_DATE");
+ public final static Property NoticeContent = new Property(3, String.class, "noticeContent", false, "NOTICE_CONTENT");
+ public final static Property SenderName = new Property(4, String.class, "senderName", false, "SENDER_NAME");
+ public final static Property IsRead = new Property(5, String.class, "isRead", false, "IS_READ");
+ }
+
+
+ public NoticeBeanDao(DaoConfig config) {
+ super(config);
+ }
+
+ public NoticeBeanDao(DaoConfig config, DaoSession daoSession) {
+ super(config, daoSession);
+ }
+
+ /** Creates the underlying database table. */
+ public static void createTable(Database db, boolean ifNotExists) {
+ String constraint = ifNotExists? "IF NOT EXISTS ": "";
+ db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_BEAN\" (" + //
+ "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
+ "\"NOTICE_TITLE\" TEXT," + // 1: noticeTitle
+ "\"NOTICE_DATE\" TEXT," + // 2: noticeDate
+ "\"NOTICE_CONTENT\" TEXT," + // 3: noticeContent
+ "\"SENDER_NAME\" TEXT," + // 4: senderName
+ "\"IS_READ\" TEXT);"); // 5: isRead
+ }
+
+ /** Drops the underlying database table. */
+ public static void dropTable(Database db, boolean ifExists) {
+ String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_BEAN\"";
+ db.execSQL(sql);
+ }
+
+ @Override
+ protected final void bindValues(DatabaseStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ protected final void bindValues(SQLiteStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ public Long readKey(Cursor cursor, int offset) {
+ return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
+ }
+
+ @Override
+ public NoticeBean readEntity(Cursor cursor, int offset) {
+ NoticeBean entity = new NoticeBean( //
+ cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
+ cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // noticeTitle
+ cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noticeDate
+ cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // noticeContent
+ cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // senderName
+ cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // isRead
+ );
+ return entity;
+ }
+
+ @Override
+ public void readEntity(Cursor cursor, NoticeBean entity, int offset) {
+ entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
+ entity.setNoticeTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
+ entity.setNoticeDate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
+ entity.setNoticeContent(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
+ entity.setSenderName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
+ entity.setIsRead(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
+ }
+
+ @Override
+ protected final Long updateKeyAfterInsert(NoticeBean entity, long rowId) {
+ entity.setId(rowId);
+ return rowId;
+ }
+
+ @Override
+ public Long getKey(NoticeBean entity) {
+ if(entity != null) {
+ return entity.getId();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean hasKey(NoticeBean entity) {
+ return entity.getId() != null;
+ }
+
+ @Override
+ protected final boolean isEntityUpdateable() {
+ return true;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
index 4ff8b3c..10c9d85 100644
--- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
+++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
@@ -2,6 +2,7 @@
import android.content.Context;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.bean.NoticeBean;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -57,7 +58,11 @@
noticeBean.setSenderName("管理员");
noticeBean.setNoticeDate(TimeOrDateUtil.timestampToDate(System.currentTimeMillis()));
noticeBean.setNoticeContent(msg.getContent());
+ noticeBean.setIsRead("1");
+ //存本地一份
+ BaseApplication.getDaoSession().insert(noticeBean);
+ //发送消息更新界面
BroadcastManager.getInstance(context).sendBroadcast(Constant.NOTICE_MSG, new Gson().toJson(noticeBean));
}
diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
index 1de7445..5f857bc 100644
--- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java
+++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
@@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
@@ -19,9 +20,10 @@
import com.casic.dcms.ui.fragment.PhonePageFragment;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
+import com.casic.dcms.utils.StatusBarColorUtil;
import com.casic.dcms.widgets.NoScrollViewPager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
-import com.qmuiteam.qmui.widget.QMUITopBarLayout;
+import com.gyf.immersionbar.ImmersionBar;
import java.util.ArrayList;
import java.util.List;
@@ -31,13 +33,12 @@
public class MainActivity extends DoubleClickExitActivity {
private static final String TAG = "MainActivity";
- @BindView(R.id.mainTopLayout)
- QMUITopBarLayout mainTopLayout;
+ @BindView(R.id.pageTitleView)
+ TextView pageTitleView;
@BindView(R.id.mainViewPager)
NoScrollViewPager mainViewPager;
@BindView(R.id.bottomNavigation)
BottomNavigationView bottomNavigation;
- private Context context = this;
private MenuItem menuItem;
private List pageList;
private BroadcastManager broadcastManager;
@@ -49,8 +50,9 @@
@Override
protected void setupTopBarLayout() {
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
- mainTopLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor));
+ StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor));
+ ImmersionBar.with(this).statusBarDarkFont(false).init();
+ pageTitleView.setText("首页");
}
@Override
@@ -88,19 +90,19 @@
switch (item.getItemId()) {
case R.id.navigation_home:
mainViewPager.setCurrentItem(0);
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("首页");
break;
case R.id.navigation_phone:
mainViewPager.setCurrentItem(1);
- mainTopLayout.setTitle("通讯录").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("通讯录");
break;
case R.id.navigation_dashboard:
mainViewPager.setCurrentItem(2);
- mainTopLayout.setTitle("消息").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("消息");
break;
case R.id.navigation_mine:
mainViewPager.setCurrentItem(3);
- mainTopLayout.setTitle("我的").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("我的");
break;
default:
break;
diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
index b8dbeb9..001fb6c 100644
--- a/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
+++ b/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
@@ -12,8 +12,10 @@
import com.casic.dcms.R;
import com.casic.dcms.adapter.SwipeViewAdapter;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.base.BaseFragment;
import com.casic.dcms.bean.NoticeBean;
+import com.casic.dcms.greendao.DaoSession;
import com.casic.dcms.ui.NoticeActivity;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -33,6 +35,7 @@
**/
public class UnreadFragment extends BaseFragment {
+ private static final String TAG = "UnreadFragment";
@BindView(R.id.swipeRecyclerView)
RecyclerView swipeRecyclerView;
@@ -41,6 +44,7 @@
private SwipeViewAdapter swipeViewAdapter;
private BroadcastManager broadcastManager;
private Gson gson;
+ private DaoSession daoSession;
@Override
protected int initLayoutView() {
@@ -55,7 +59,12 @@
@Override
protected void initData() {
gson = new Gson();
- swipeViewAdapter = new SwipeViewAdapter(getContext());
+ daoSession = BaseApplication.getDaoSession();
+ swipeViewAdapter = new SwipeViewAdapter(context);
+ //加载历史数据
+ noticeBeans = daoSession.loadAll(NoticeBean.class);
+ swipeViewAdapter.setData(noticeBeans);
+
broadcastManager = BroadcastManager.getInstance(context);
broadcastManager.addAction(Constant.NOTICE_MSG, new BroadcastReceiver() {
@Override
@@ -67,9 +76,10 @@
assert data != null;
NoticeBean noticeBean = gson.fromJson(data, NoticeBean.class);
noticeBeans.add(noticeBean);
+ //更新数据
+ swipeViewAdapter.setData(noticeBeans);
}
}
- swipeViewAdapter.setData(noticeBeans);
}
});
}
@@ -78,7 +88,9 @@
QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() {
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
- swipeViewAdapter.remove(viewHolder.getAdapterPosition());
+ int position = viewHolder.getAdapterPosition();
+ daoSession.delete(noticeBeans.get(position));
+ swipeViewAdapter.remove(position);
}
@Override
@@ -89,15 +101,16 @@
@Override
public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) {
super.onClickAction(swipeAction, selected, action);
- swipeViewAdapter.remove(selected.getAdapterPosition());
+ int position = selected.getAdapterPosition();
+ daoSession.delete(noticeBeans.get(position));
+ swipeViewAdapter.remove(position);
}
});
swipeAction.attachToRecyclerView(swipeRecyclerView);
swipeRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()) {
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
- return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
+ return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
});
swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
@@ -107,6 +120,9 @@
public void onClick(int position) {
//查看之后,未读消息变为已读消息
NoticeBean noticeBean = noticeBeans.get(position);
+ noticeBean.setIsRead("0");
+ daoSession.update(noticeBean);
+
Intent intent = new Intent(context, NoticeActivity.class);
intent.putExtra("noticeBeanJson", new Gson().toJson(noticeBean));
startActivity(intent);
@@ -117,6 +133,6 @@
@Override
public void onDestroyView() {
super.onDestroyView();
- broadcastManager.destroy(Constant.LOGIN_OUT_ACTION);
+ broadcastManager.destroy(Constant.NOTICE_MSG);
}
}
diff --git a/app/build.gradle b/app/build.gradle
index ae31f07..c4aa488 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
+apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 30
@@ -31,6 +32,12 @@
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
+
+ greendao {
+ schemaVersion 1//数据库版本号
+ targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录
+ daoPackage 'com.casic.dcms.greendao'//设置DaoMaster、DaoSession、Dao包名
+ }
}
dependencies {
@@ -38,7 +45,7 @@
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
@@ -81,4 +88,10 @@
implementation 'com.github.huangyanbin:SmartTable:1.7.1'
implementation 'com.getui:gtsdk:3.1.4.0' //个推SDK
implementation 'com.getui:gtc:3.1.0.0' //个推核心组件
+ //数据库框架
+ implementation 'org.greenrobot:greendao:3.3.0'
+ //沉浸式状态栏。基础依赖包,必须要依赖
+ implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
+ //fragment快速实现
+ implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 35a9c86..d5c56ab 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -57,7 +57,7 @@
+ android:value="${GETUI_APPID}" />
>, DaoConfig>
+ daoConfigMap) {
+ super(db);
+
+ noticeBeanDaoConfig = daoConfigMap.get(NoticeBeanDao.class).clone();
+ noticeBeanDaoConfig.initIdentityScope(type);
+
+ noticeBeanDao = new NoticeBeanDao(noticeBeanDaoConfig, this);
+
+ registerDao(NoticeBean.class, noticeBeanDao);
+ }
+
+ public void clear() {
+ noticeBeanDaoConfig.clearIdentityScope();
+ }
+
+ public NoticeBeanDao getNoticeBeanDao() {
+ return noticeBeanDao;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
new file mode 100644
index 0000000..259eb85
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
@@ -0,0 +1,185 @@
+package com.casic.dcms.greendao;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteStatement;
+
+import org.greenrobot.greendao.AbstractDao;
+import org.greenrobot.greendao.Property;
+import org.greenrobot.greendao.internal.DaoConfig;
+import org.greenrobot.greendao.database.Database;
+import org.greenrobot.greendao.database.DatabaseStatement;
+
+import com.casic.dcms.bean.NoticeBean;
+
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
+/**
+ * DAO for table "NOTICE_BEAN".
+*/
+public class NoticeBeanDao extends AbstractDao {
+
+ public static final String TABLENAME = "NOTICE_BEAN";
+
+ /**
+ * Properties of entity NoticeBean.
+ * Can be used for QueryBuilder and for referencing column names.
+ */
+ public static class Properties {
+ public final static Property Id = new Property(0, Long.class, "id", true, "_id");
+ public final static Property NoticeTitle = new Property(1, String.class, "noticeTitle", false, "NOTICE_TITLE");
+ public final static Property NoticeDate = new Property(2, String.class, "noticeDate", false, "NOTICE_DATE");
+ public final static Property NoticeContent = new Property(3, String.class, "noticeContent", false, "NOTICE_CONTENT");
+ public final static Property SenderName = new Property(4, String.class, "senderName", false, "SENDER_NAME");
+ public final static Property IsRead = new Property(5, String.class, "isRead", false, "IS_READ");
+ }
+
+
+ public NoticeBeanDao(DaoConfig config) {
+ super(config);
+ }
+
+ public NoticeBeanDao(DaoConfig config, DaoSession daoSession) {
+ super(config, daoSession);
+ }
+
+ /** Creates the underlying database table. */
+ public static void createTable(Database db, boolean ifNotExists) {
+ String constraint = ifNotExists? "IF NOT EXISTS ": "";
+ db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_BEAN\" (" + //
+ "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
+ "\"NOTICE_TITLE\" TEXT," + // 1: noticeTitle
+ "\"NOTICE_DATE\" TEXT," + // 2: noticeDate
+ "\"NOTICE_CONTENT\" TEXT," + // 3: noticeContent
+ "\"SENDER_NAME\" TEXT," + // 4: senderName
+ "\"IS_READ\" TEXT);"); // 5: isRead
+ }
+
+ /** Drops the underlying database table. */
+ public static void dropTable(Database db, boolean ifExists) {
+ String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_BEAN\"";
+ db.execSQL(sql);
+ }
+
+ @Override
+ protected final void bindValues(DatabaseStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ protected final void bindValues(SQLiteStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ public Long readKey(Cursor cursor, int offset) {
+ return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
+ }
+
+ @Override
+ public NoticeBean readEntity(Cursor cursor, int offset) {
+ NoticeBean entity = new NoticeBean( //
+ cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
+ cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // noticeTitle
+ cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noticeDate
+ cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // noticeContent
+ cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // senderName
+ cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // isRead
+ );
+ return entity;
+ }
+
+ @Override
+ public void readEntity(Cursor cursor, NoticeBean entity, int offset) {
+ entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
+ entity.setNoticeTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
+ entity.setNoticeDate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
+ entity.setNoticeContent(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
+ entity.setSenderName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
+ entity.setIsRead(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
+ }
+
+ @Override
+ protected final Long updateKeyAfterInsert(NoticeBean entity, long rowId) {
+ entity.setId(rowId);
+ return rowId;
+ }
+
+ @Override
+ public Long getKey(NoticeBean entity) {
+ if(entity != null) {
+ return entity.getId();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean hasKey(NoticeBean entity) {
+ return entity.getId() != null;
+ }
+
+ @Override
+ protected final boolean isEntityUpdateable() {
+ return true;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
index 4ff8b3c..10c9d85 100644
--- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
+++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
@@ -2,6 +2,7 @@
import android.content.Context;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.bean.NoticeBean;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -57,7 +58,11 @@
noticeBean.setSenderName("管理员");
noticeBean.setNoticeDate(TimeOrDateUtil.timestampToDate(System.currentTimeMillis()));
noticeBean.setNoticeContent(msg.getContent());
+ noticeBean.setIsRead("1");
+ //存本地一份
+ BaseApplication.getDaoSession().insert(noticeBean);
+ //发送消息更新界面
BroadcastManager.getInstance(context).sendBroadcast(Constant.NOTICE_MSG, new Gson().toJson(noticeBean));
}
diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
index 1de7445..5f857bc 100644
--- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java
+++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
@@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
@@ -19,9 +20,10 @@
import com.casic.dcms.ui.fragment.PhonePageFragment;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
+import com.casic.dcms.utils.StatusBarColorUtil;
import com.casic.dcms.widgets.NoScrollViewPager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
-import com.qmuiteam.qmui.widget.QMUITopBarLayout;
+import com.gyf.immersionbar.ImmersionBar;
import java.util.ArrayList;
import java.util.List;
@@ -31,13 +33,12 @@
public class MainActivity extends DoubleClickExitActivity {
private static final String TAG = "MainActivity";
- @BindView(R.id.mainTopLayout)
- QMUITopBarLayout mainTopLayout;
+ @BindView(R.id.pageTitleView)
+ TextView pageTitleView;
@BindView(R.id.mainViewPager)
NoScrollViewPager mainViewPager;
@BindView(R.id.bottomNavigation)
BottomNavigationView bottomNavigation;
- private Context context = this;
private MenuItem menuItem;
private List pageList;
private BroadcastManager broadcastManager;
@@ -49,8 +50,9 @@
@Override
protected void setupTopBarLayout() {
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
- mainTopLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor));
+ StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor));
+ ImmersionBar.with(this).statusBarDarkFont(false).init();
+ pageTitleView.setText("首页");
}
@Override
@@ -88,19 +90,19 @@
switch (item.getItemId()) {
case R.id.navigation_home:
mainViewPager.setCurrentItem(0);
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("首页");
break;
case R.id.navigation_phone:
mainViewPager.setCurrentItem(1);
- mainTopLayout.setTitle("通讯录").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("通讯录");
break;
case R.id.navigation_dashboard:
mainViewPager.setCurrentItem(2);
- mainTopLayout.setTitle("消息").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("消息");
break;
case R.id.navigation_mine:
mainViewPager.setCurrentItem(3);
- mainTopLayout.setTitle("我的").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("我的");
break;
default:
break;
diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
index b8dbeb9..001fb6c 100644
--- a/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
+++ b/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
@@ -12,8 +12,10 @@
import com.casic.dcms.R;
import com.casic.dcms.adapter.SwipeViewAdapter;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.base.BaseFragment;
import com.casic.dcms.bean.NoticeBean;
+import com.casic.dcms.greendao.DaoSession;
import com.casic.dcms.ui.NoticeActivity;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -33,6 +35,7 @@
**/
public class UnreadFragment extends BaseFragment {
+ private static final String TAG = "UnreadFragment";
@BindView(R.id.swipeRecyclerView)
RecyclerView swipeRecyclerView;
@@ -41,6 +44,7 @@
private SwipeViewAdapter swipeViewAdapter;
private BroadcastManager broadcastManager;
private Gson gson;
+ private DaoSession daoSession;
@Override
protected int initLayoutView() {
@@ -55,7 +59,12 @@
@Override
protected void initData() {
gson = new Gson();
- swipeViewAdapter = new SwipeViewAdapter(getContext());
+ daoSession = BaseApplication.getDaoSession();
+ swipeViewAdapter = new SwipeViewAdapter(context);
+ //加载历史数据
+ noticeBeans = daoSession.loadAll(NoticeBean.class);
+ swipeViewAdapter.setData(noticeBeans);
+
broadcastManager = BroadcastManager.getInstance(context);
broadcastManager.addAction(Constant.NOTICE_MSG, new BroadcastReceiver() {
@Override
@@ -67,9 +76,10 @@
assert data != null;
NoticeBean noticeBean = gson.fromJson(data, NoticeBean.class);
noticeBeans.add(noticeBean);
+ //更新数据
+ swipeViewAdapter.setData(noticeBeans);
}
}
- swipeViewAdapter.setData(noticeBeans);
}
});
}
@@ -78,7 +88,9 @@
QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() {
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
- swipeViewAdapter.remove(viewHolder.getAdapterPosition());
+ int position = viewHolder.getAdapterPosition();
+ daoSession.delete(noticeBeans.get(position));
+ swipeViewAdapter.remove(position);
}
@Override
@@ -89,15 +101,16 @@
@Override
public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) {
super.onClickAction(swipeAction, selected, action);
- swipeViewAdapter.remove(selected.getAdapterPosition());
+ int position = selected.getAdapterPosition();
+ daoSession.delete(noticeBeans.get(position));
+ swipeViewAdapter.remove(position);
}
});
swipeAction.attachToRecyclerView(swipeRecyclerView);
swipeRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()) {
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
- return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
+ return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
});
swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
@@ -107,6 +120,9 @@
public void onClick(int position) {
//查看之后,未读消息变为已读消息
NoticeBean noticeBean = noticeBeans.get(position);
+ noticeBean.setIsRead("0");
+ daoSession.update(noticeBean);
+
Intent intent = new Intent(context, NoticeActivity.class);
intent.putExtra("noticeBeanJson", new Gson().toJson(noticeBean));
startActivity(intent);
@@ -117,6 +133,6 @@
@Override
public void onDestroyView() {
super.onDestroyView();
- broadcastManager.destroy(Constant.LOGIN_OUT_ACTION);
+ broadcastManager.destroy(Constant.NOTICE_MSG);
}
}
diff --git a/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java b/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java
new file mode 100644
index 0000000..9e5109c
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java
@@ -0,0 +1,43 @@
+package com.casic.dcms.utils;
+
+import android.app.Activity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.LinearLayout;
+
+public class StatusBarColorUtil {
+ public static void setColor(Activity activity, int color) {
+ //限制android系统的版本
+ // 设置状态栏透明
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ // 生成一个状态栏大小的矩形
+ View statusView = createStatusView(activity, color);
+ // 添加 statusView 到布局中
+ ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
+ decorView.addView(statusView);
+ // 设置根布局的参数
+ ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
+ rootView.setFitsSystemWindows(true);
+ rootView.setClipToPadding(true);
+ }
+
+ /**
+ * 生成一个和状态栏大小相同的矩形条
+ *
+ * @param activity 需要设置的activity
+ * @param color 状态栏颜色值
+ * @return 状态栏矩形条
+ */
+ private static View createStatusView(Activity activity, int color) {
+ // 获得状态栏高度
+ int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
+ int statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);
+ // 绘制一个和状态栏一样高的矩形
+ View statusView = new View(activity);
+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
+ statusView.setLayoutParams(params);
+ statusView.setBackgroundColor(color);
+ return statusView;
+ }
+}
diff --git a/app/build.gradle b/app/build.gradle
index ae31f07..c4aa488 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
+apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 30
@@ -31,6 +32,12 @@
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
+
+ greendao {
+ schemaVersion 1//数据库版本号
+ targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录
+ daoPackage 'com.casic.dcms.greendao'//设置DaoMaster、DaoSession、Dao包名
+ }
}
dependencies {
@@ -38,7 +45,7 @@
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
@@ -81,4 +88,10 @@
implementation 'com.github.huangyanbin:SmartTable:1.7.1'
implementation 'com.getui:gtsdk:3.1.4.0' //个推SDK
implementation 'com.getui:gtc:3.1.0.0' //个推核心组件
+ //数据库框架
+ implementation 'org.greenrobot:greendao:3.3.0'
+ //沉浸式状态栏。基础依赖包,必须要依赖
+ implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
+ //fragment快速实现
+ implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 35a9c86..d5c56ab 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -57,7 +57,7 @@
+ android:value="${GETUI_APPID}" />
>, DaoConfig>
+ daoConfigMap) {
+ super(db);
+
+ noticeBeanDaoConfig = daoConfigMap.get(NoticeBeanDao.class).clone();
+ noticeBeanDaoConfig.initIdentityScope(type);
+
+ noticeBeanDao = new NoticeBeanDao(noticeBeanDaoConfig, this);
+
+ registerDao(NoticeBean.class, noticeBeanDao);
+ }
+
+ public void clear() {
+ noticeBeanDaoConfig.clearIdentityScope();
+ }
+
+ public NoticeBeanDao getNoticeBeanDao() {
+ return noticeBeanDao;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
new file mode 100644
index 0000000..259eb85
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
@@ -0,0 +1,185 @@
+package com.casic.dcms.greendao;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteStatement;
+
+import org.greenrobot.greendao.AbstractDao;
+import org.greenrobot.greendao.Property;
+import org.greenrobot.greendao.internal.DaoConfig;
+import org.greenrobot.greendao.database.Database;
+import org.greenrobot.greendao.database.DatabaseStatement;
+
+import com.casic.dcms.bean.NoticeBean;
+
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
+/**
+ * DAO for table "NOTICE_BEAN".
+*/
+public class NoticeBeanDao extends AbstractDao {
+
+ public static final String TABLENAME = "NOTICE_BEAN";
+
+ /**
+ * Properties of entity NoticeBean.
+ * Can be used for QueryBuilder and for referencing column names.
+ */
+ public static class Properties {
+ public final static Property Id = new Property(0, Long.class, "id", true, "_id");
+ public final static Property NoticeTitle = new Property(1, String.class, "noticeTitle", false, "NOTICE_TITLE");
+ public final static Property NoticeDate = new Property(2, String.class, "noticeDate", false, "NOTICE_DATE");
+ public final static Property NoticeContent = new Property(3, String.class, "noticeContent", false, "NOTICE_CONTENT");
+ public final static Property SenderName = new Property(4, String.class, "senderName", false, "SENDER_NAME");
+ public final static Property IsRead = new Property(5, String.class, "isRead", false, "IS_READ");
+ }
+
+
+ public NoticeBeanDao(DaoConfig config) {
+ super(config);
+ }
+
+ public NoticeBeanDao(DaoConfig config, DaoSession daoSession) {
+ super(config, daoSession);
+ }
+
+ /** Creates the underlying database table. */
+ public static void createTable(Database db, boolean ifNotExists) {
+ String constraint = ifNotExists? "IF NOT EXISTS ": "";
+ db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_BEAN\" (" + //
+ "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
+ "\"NOTICE_TITLE\" TEXT," + // 1: noticeTitle
+ "\"NOTICE_DATE\" TEXT," + // 2: noticeDate
+ "\"NOTICE_CONTENT\" TEXT," + // 3: noticeContent
+ "\"SENDER_NAME\" TEXT," + // 4: senderName
+ "\"IS_READ\" TEXT);"); // 5: isRead
+ }
+
+ /** Drops the underlying database table. */
+ public static void dropTable(Database db, boolean ifExists) {
+ String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_BEAN\"";
+ db.execSQL(sql);
+ }
+
+ @Override
+ protected final void bindValues(DatabaseStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ protected final void bindValues(SQLiteStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ public Long readKey(Cursor cursor, int offset) {
+ return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
+ }
+
+ @Override
+ public NoticeBean readEntity(Cursor cursor, int offset) {
+ NoticeBean entity = new NoticeBean( //
+ cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
+ cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // noticeTitle
+ cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noticeDate
+ cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // noticeContent
+ cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // senderName
+ cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // isRead
+ );
+ return entity;
+ }
+
+ @Override
+ public void readEntity(Cursor cursor, NoticeBean entity, int offset) {
+ entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
+ entity.setNoticeTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
+ entity.setNoticeDate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
+ entity.setNoticeContent(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
+ entity.setSenderName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
+ entity.setIsRead(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
+ }
+
+ @Override
+ protected final Long updateKeyAfterInsert(NoticeBean entity, long rowId) {
+ entity.setId(rowId);
+ return rowId;
+ }
+
+ @Override
+ public Long getKey(NoticeBean entity) {
+ if(entity != null) {
+ return entity.getId();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean hasKey(NoticeBean entity) {
+ return entity.getId() != null;
+ }
+
+ @Override
+ protected final boolean isEntityUpdateable() {
+ return true;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
index 4ff8b3c..10c9d85 100644
--- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
+++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
@@ -2,6 +2,7 @@
import android.content.Context;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.bean.NoticeBean;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -57,7 +58,11 @@
noticeBean.setSenderName("管理员");
noticeBean.setNoticeDate(TimeOrDateUtil.timestampToDate(System.currentTimeMillis()));
noticeBean.setNoticeContent(msg.getContent());
+ noticeBean.setIsRead("1");
+ //存本地一份
+ BaseApplication.getDaoSession().insert(noticeBean);
+ //发送消息更新界面
BroadcastManager.getInstance(context).sendBroadcast(Constant.NOTICE_MSG, new Gson().toJson(noticeBean));
}
diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
index 1de7445..5f857bc 100644
--- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java
+++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
@@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
@@ -19,9 +20,10 @@
import com.casic.dcms.ui.fragment.PhonePageFragment;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
+import com.casic.dcms.utils.StatusBarColorUtil;
import com.casic.dcms.widgets.NoScrollViewPager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
-import com.qmuiteam.qmui.widget.QMUITopBarLayout;
+import com.gyf.immersionbar.ImmersionBar;
import java.util.ArrayList;
import java.util.List;
@@ -31,13 +33,12 @@
public class MainActivity extends DoubleClickExitActivity {
private static final String TAG = "MainActivity";
- @BindView(R.id.mainTopLayout)
- QMUITopBarLayout mainTopLayout;
+ @BindView(R.id.pageTitleView)
+ TextView pageTitleView;
@BindView(R.id.mainViewPager)
NoScrollViewPager mainViewPager;
@BindView(R.id.bottomNavigation)
BottomNavigationView bottomNavigation;
- private Context context = this;
private MenuItem menuItem;
private List pageList;
private BroadcastManager broadcastManager;
@@ -49,8 +50,9 @@
@Override
protected void setupTopBarLayout() {
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
- mainTopLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor));
+ StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor));
+ ImmersionBar.with(this).statusBarDarkFont(false).init();
+ pageTitleView.setText("首页");
}
@Override
@@ -88,19 +90,19 @@
switch (item.getItemId()) {
case R.id.navigation_home:
mainViewPager.setCurrentItem(0);
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("首页");
break;
case R.id.navigation_phone:
mainViewPager.setCurrentItem(1);
- mainTopLayout.setTitle("通讯录").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("通讯录");
break;
case R.id.navigation_dashboard:
mainViewPager.setCurrentItem(2);
- mainTopLayout.setTitle("消息").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("消息");
break;
case R.id.navigation_mine:
mainViewPager.setCurrentItem(3);
- mainTopLayout.setTitle("我的").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("我的");
break;
default:
break;
diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
index b8dbeb9..001fb6c 100644
--- a/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
+++ b/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
@@ -12,8 +12,10 @@
import com.casic.dcms.R;
import com.casic.dcms.adapter.SwipeViewAdapter;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.base.BaseFragment;
import com.casic.dcms.bean.NoticeBean;
+import com.casic.dcms.greendao.DaoSession;
import com.casic.dcms.ui.NoticeActivity;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -33,6 +35,7 @@
**/
public class UnreadFragment extends BaseFragment {
+ private static final String TAG = "UnreadFragment";
@BindView(R.id.swipeRecyclerView)
RecyclerView swipeRecyclerView;
@@ -41,6 +44,7 @@
private SwipeViewAdapter swipeViewAdapter;
private BroadcastManager broadcastManager;
private Gson gson;
+ private DaoSession daoSession;
@Override
protected int initLayoutView() {
@@ -55,7 +59,12 @@
@Override
protected void initData() {
gson = new Gson();
- swipeViewAdapter = new SwipeViewAdapter(getContext());
+ daoSession = BaseApplication.getDaoSession();
+ swipeViewAdapter = new SwipeViewAdapter(context);
+ //加载历史数据
+ noticeBeans = daoSession.loadAll(NoticeBean.class);
+ swipeViewAdapter.setData(noticeBeans);
+
broadcastManager = BroadcastManager.getInstance(context);
broadcastManager.addAction(Constant.NOTICE_MSG, new BroadcastReceiver() {
@Override
@@ -67,9 +76,10 @@
assert data != null;
NoticeBean noticeBean = gson.fromJson(data, NoticeBean.class);
noticeBeans.add(noticeBean);
+ //更新数据
+ swipeViewAdapter.setData(noticeBeans);
}
}
- swipeViewAdapter.setData(noticeBeans);
}
});
}
@@ -78,7 +88,9 @@
QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() {
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
- swipeViewAdapter.remove(viewHolder.getAdapterPosition());
+ int position = viewHolder.getAdapterPosition();
+ daoSession.delete(noticeBeans.get(position));
+ swipeViewAdapter.remove(position);
}
@Override
@@ -89,15 +101,16 @@
@Override
public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) {
super.onClickAction(swipeAction, selected, action);
- swipeViewAdapter.remove(selected.getAdapterPosition());
+ int position = selected.getAdapterPosition();
+ daoSession.delete(noticeBeans.get(position));
+ swipeViewAdapter.remove(position);
}
});
swipeAction.attachToRecyclerView(swipeRecyclerView);
swipeRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()) {
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
- return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
+ return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
});
swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
@@ -107,6 +120,9 @@
public void onClick(int position) {
//查看之后,未读消息变为已读消息
NoticeBean noticeBean = noticeBeans.get(position);
+ noticeBean.setIsRead("0");
+ daoSession.update(noticeBean);
+
Intent intent = new Intent(context, NoticeActivity.class);
intent.putExtra("noticeBeanJson", new Gson().toJson(noticeBean));
startActivity(intent);
@@ -117,6 +133,6 @@
@Override
public void onDestroyView() {
super.onDestroyView();
- broadcastManager.destroy(Constant.LOGIN_OUT_ACTION);
+ broadcastManager.destroy(Constant.NOTICE_MSG);
}
}
diff --git a/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java b/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java
new file mode 100644
index 0000000..9e5109c
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java
@@ -0,0 +1,43 @@
+package com.casic.dcms.utils;
+
+import android.app.Activity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.LinearLayout;
+
+public class StatusBarColorUtil {
+ public static void setColor(Activity activity, int color) {
+ //限制android系统的版本
+ // 设置状态栏透明
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ // 生成一个状态栏大小的矩形
+ View statusView = createStatusView(activity, color);
+ // 添加 statusView 到布局中
+ ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
+ decorView.addView(statusView);
+ // 设置根布局的参数
+ ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
+ rootView.setFitsSystemWindows(true);
+ rootView.setClipToPadding(true);
+ }
+
+ /**
+ * 生成一个和状态栏大小相同的矩形条
+ *
+ * @param activity 需要设置的activity
+ * @param color 状态栏颜色值
+ * @return 状态栏矩形条
+ */
+ private static View createStatusView(Activity activity, int color) {
+ // 获得状态栏高度
+ int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
+ int statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);
+ // 绘制一个和状态栏一样高的矩形
+ View statusView = new View(activity);
+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
+ statusView.setLayoutParams(params);
+ statusView.setBackgroundColor(color);
+ return statusView;
+ }
+}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 45f3e3d..8e25113 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -5,11 +5,16 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
+ android:background="@color/mainThemeColor"
+ android:gravity="center"
+ android:paddingVertical="15dp"
+ android:text="@string/app_name"
+ android:textColor="@color/white"
+ android:textSize="@dimen/titleFontSize" />
+ android:value="${GETUI_APPID}" />
>, DaoConfig>
+ daoConfigMap) {
+ super(db);
+
+ noticeBeanDaoConfig = daoConfigMap.get(NoticeBeanDao.class).clone();
+ noticeBeanDaoConfig.initIdentityScope(type);
+
+ noticeBeanDao = new NoticeBeanDao(noticeBeanDaoConfig, this);
+
+ registerDao(NoticeBean.class, noticeBeanDao);
+ }
+
+ public void clear() {
+ noticeBeanDaoConfig.clearIdentityScope();
+ }
+
+ public NoticeBeanDao getNoticeBeanDao() {
+ return noticeBeanDao;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
new file mode 100644
index 0000000..259eb85
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
@@ -0,0 +1,185 @@
+package com.casic.dcms.greendao;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteStatement;
+
+import org.greenrobot.greendao.AbstractDao;
+import org.greenrobot.greendao.Property;
+import org.greenrobot.greendao.internal.DaoConfig;
+import org.greenrobot.greendao.database.Database;
+import org.greenrobot.greendao.database.DatabaseStatement;
+
+import com.casic.dcms.bean.NoticeBean;
+
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
+/**
+ * DAO for table "NOTICE_BEAN".
+*/
+public class NoticeBeanDao extends AbstractDao {
+
+ public static final String TABLENAME = "NOTICE_BEAN";
+
+ /**
+ * Properties of entity NoticeBean.
+ * Can be used for QueryBuilder and for referencing column names.
+ */
+ public static class Properties {
+ public final static Property Id = new Property(0, Long.class, "id", true, "_id");
+ public final static Property NoticeTitle = new Property(1, String.class, "noticeTitle", false, "NOTICE_TITLE");
+ public final static Property NoticeDate = new Property(2, String.class, "noticeDate", false, "NOTICE_DATE");
+ public final static Property NoticeContent = new Property(3, String.class, "noticeContent", false, "NOTICE_CONTENT");
+ public final static Property SenderName = new Property(4, String.class, "senderName", false, "SENDER_NAME");
+ public final static Property IsRead = new Property(5, String.class, "isRead", false, "IS_READ");
+ }
+
+
+ public NoticeBeanDao(DaoConfig config) {
+ super(config);
+ }
+
+ public NoticeBeanDao(DaoConfig config, DaoSession daoSession) {
+ super(config, daoSession);
+ }
+
+ /** Creates the underlying database table. */
+ public static void createTable(Database db, boolean ifNotExists) {
+ String constraint = ifNotExists? "IF NOT EXISTS ": "";
+ db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_BEAN\" (" + //
+ "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
+ "\"NOTICE_TITLE\" TEXT," + // 1: noticeTitle
+ "\"NOTICE_DATE\" TEXT," + // 2: noticeDate
+ "\"NOTICE_CONTENT\" TEXT," + // 3: noticeContent
+ "\"SENDER_NAME\" TEXT," + // 4: senderName
+ "\"IS_READ\" TEXT);"); // 5: isRead
+ }
+
+ /** Drops the underlying database table. */
+ public static void dropTable(Database db, boolean ifExists) {
+ String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_BEAN\"";
+ db.execSQL(sql);
+ }
+
+ @Override
+ protected final void bindValues(DatabaseStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ protected final void bindValues(SQLiteStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ public Long readKey(Cursor cursor, int offset) {
+ return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
+ }
+
+ @Override
+ public NoticeBean readEntity(Cursor cursor, int offset) {
+ NoticeBean entity = new NoticeBean( //
+ cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
+ cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // noticeTitle
+ cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noticeDate
+ cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // noticeContent
+ cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // senderName
+ cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // isRead
+ );
+ return entity;
+ }
+
+ @Override
+ public void readEntity(Cursor cursor, NoticeBean entity, int offset) {
+ entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
+ entity.setNoticeTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
+ entity.setNoticeDate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
+ entity.setNoticeContent(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
+ entity.setSenderName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
+ entity.setIsRead(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
+ }
+
+ @Override
+ protected final Long updateKeyAfterInsert(NoticeBean entity, long rowId) {
+ entity.setId(rowId);
+ return rowId;
+ }
+
+ @Override
+ public Long getKey(NoticeBean entity) {
+ if(entity != null) {
+ return entity.getId();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean hasKey(NoticeBean entity) {
+ return entity.getId() != null;
+ }
+
+ @Override
+ protected final boolean isEntityUpdateable() {
+ return true;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
index 4ff8b3c..10c9d85 100644
--- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
+++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
@@ -2,6 +2,7 @@
import android.content.Context;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.bean.NoticeBean;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -57,7 +58,11 @@
noticeBean.setSenderName("管理员");
noticeBean.setNoticeDate(TimeOrDateUtil.timestampToDate(System.currentTimeMillis()));
noticeBean.setNoticeContent(msg.getContent());
+ noticeBean.setIsRead("1");
+ //存本地一份
+ BaseApplication.getDaoSession().insert(noticeBean);
+ //发送消息更新界面
BroadcastManager.getInstance(context).sendBroadcast(Constant.NOTICE_MSG, new Gson().toJson(noticeBean));
}
diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
index 1de7445..5f857bc 100644
--- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java
+++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
@@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
@@ -19,9 +20,10 @@
import com.casic.dcms.ui.fragment.PhonePageFragment;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
+import com.casic.dcms.utils.StatusBarColorUtil;
import com.casic.dcms.widgets.NoScrollViewPager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
-import com.qmuiteam.qmui.widget.QMUITopBarLayout;
+import com.gyf.immersionbar.ImmersionBar;
import java.util.ArrayList;
import java.util.List;
@@ -31,13 +33,12 @@
public class MainActivity extends DoubleClickExitActivity {
private static final String TAG = "MainActivity";
- @BindView(R.id.mainTopLayout)
- QMUITopBarLayout mainTopLayout;
+ @BindView(R.id.pageTitleView)
+ TextView pageTitleView;
@BindView(R.id.mainViewPager)
NoScrollViewPager mainViewPager;
@BindView(R.id.bottomNavigation)
BottomNavigationView bottomNavigation;
- private Context context = this;
private MenuItem menuItem;
private List pageList;
private BroadcastManager broadcastManager;
@@ -49,8 +50,9 @@
@Override
protected void setupTopBarLayout() {
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
- mainTopLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor));
+ StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor));
+ ImmersionBar.with(this).statusBarDarkFont(false).init();
+ pageTitleView.setText("首页");
}
@Override
@@ -88,19 +90,19 @@
switch (item.getItemId()) {
case R.id.navigation_home:
mainViewPager.setCurrentItem(0);
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("首页");
break;
case R.id.navigation_phone:
mainViewPager.setCurrentItem(1);
- mainTopLayout.setTitle("通讯录").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("通讯录");
break;
case R.id.navigation_dashboard:
mainViewPager.setCurrentItem(2);
- mainTopLayout.setTitle("消息").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("消息");
break;
case R.id.navigation_mine:
mainViewPager.setCurrentItem(3);
- mainTopLayout.setTitle("我的").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("我的");
break;
default:
break;
diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
index b8dbeb9..001fb6c 100644
--- a/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
+++ b/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
@@ -12,8 +12,10 @@
import com.casic.dcms.R;
import com.casic.dcms.adapter.SwipeViewAdapter;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.base.BaseFragment;
import com.casic.dcms.bean.NoticeBean;
+import com.casic.dcms.greendao.DaoSession;
import com.casic.dcms.ui.NoticeActivity;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -33,6 +35,7 @@
**/
public class UnreadFragment extends BaseFragment {
+ private static final String TAG = "UnreadFragment";
@BindView(R.id.swipeRecyclerView)
RecyclerView swipeRecyclerView;
@@ -41,6 +44,7 @@
private SwipeViewAdapter swipeViewAdapter;
private BroadcastManager broadcastManager;
private Gson gson;
+ private DaoSession daoSession;
@Override
protected int initLayoutView() {
@@ -55,7 +59,12 @@
@Override
protected void initData() {
gson = new Gson();
- swipeViewAdapter = new SwipeViewAdapter(getContext());
+ daoSession = BaseApplication.getDaoSession();
+ swipeViewAdapter = new SwipeViewAdapter(context);
+ //加载历史数据
+ noticeBeans = daoSession.loadAll(NoticeBean.class);
+ swipeViewAdapter.setData(noticeBeans);
+
broadcastManager = BroadcastManager.getInstance(context);
broadcastManager.addAction(Constant.NOTICE_MSG, new BroadcastReceiver() {
@Override
@@ -67,9 +76,10 @@
assert data != null;
NoticeBean noticeBean = gson.fromJson(data, NoticeBean.class);
noticeBeans.add(noticeBean);
+ //更新数据
+ swipeViewAdapter.setData(noticeBeans);
}
}
- swipeViewAdapter.setData(noticeBeans);
}
});
}
@@ -78,7 +88,9 @@
QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() {
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
- swipeViewAdapter.remove(viewHolder.getAdapterPosition());
+ int position = viewHolder.getAdapterPosition();
+ daoSession.delete(noticeBeans.get(position));
+ swipeViewAdapter.remove(position);
}
@Override
@@ -89,15 +101,16 @@
@Override
public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) {
super.onClickAction(swipeAction, selected, action);
- swipeViewAdapter.remove(selected.getAdapterPosition());
+ int position = selected.getAdapterPosition();
+ daoSession.delete(noticeBeans.get(position));
+ swipeViewAdapter.remove(position);
}
});
swipeAction.attachToRecyclerView(swipeRecyclerView);
swipeRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()) {
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
- return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
+ return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
});
swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
@@ -107,6 +120,9 @@
public void onClick(int position) {
//查看之后,未读消息变为已读消息
NoticeBean noticeBean = noticeBeans.get(position);
+ noticeBean.setIsRead("0");
+ daoSession.update(noticeBean);
+
Intent intent = new Intent(context, NoticeActivity.class);
intent.putExtra("noticeBeanJson", new Gson().toJson(noticeBean));
startActivity(intent);
@@ -117,6 +133,6 @@
@Override
public void onDestroyView() {
super.onDestroyView();
- broadcastManager.destroy(Constant.LOGIN_OUT_ACTION);
+ broadcastManager.destroy(Constant.NOTICE_MSG);
}
}
diff --git a/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java b/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java
new file mode 100644
index 0000000..9e5109c
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java
@@ -0,0 +1,43 @@
+package com.casic.dcms.utils;
+
+import android.app.Activity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.LinearLayout;
+
+public class StatusBarColorUtil {
+ public static void setColor(Activity activity, int color) {
+ //限制android系统的版本
+ // 设置状态栏透明
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ // 生成一个状态栏大小的矩形
+ View statusView = createStatusView(activity, color);
+ // 添加 statusView 到布局中
+ ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
+ decorView.addView(statusView);
+ // 设置根布局的参数
+ ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
+ rootView.setFitsSystemWindows(true);
+ rootView.setClipToPadding(true);
+ }
+
+ /**
+ * 生成一个和状态栏大小相同的矩形条
+ *
+ * @param activity 需要设置的activity
+ * @param color 状态栏颜色值
+ * @return 状态栏矩形条
+ */
+ private static View createStatusView(Activity activity, int color) {
+ // 获得状态栏高度
+ int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
+ int statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);
+ // 绘制一个和状态栏一样高的矩形
+ View statusView = new View(activity);
+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
+ statusView.setLayoutParams(params);
+ statusView.setBackgroundColor(color);
+ return statusView;
+ }
+}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 45f3e3d..8e25113 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -5,11 +5,16 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
+ android:background="@color/mainThemeColor"
+ android:gravity="center"
+ android:paddingVertical="15dp"
+ android:text="@string/app_name"
+ android:textColor="@color/white"
+ android:textSize="@dimen/titleFontSize" />
+ android:layout_height="wrap_content">
+ android:value="${GETUI_APPID}" />
>, DaoConfig>
+ daoConfigMap) {
+ super(db);
+
+ noticeBeanDaoConfig = daoConfigMap.get(NoticeBeanDao.class).clone();
+ noticeBeanDaoConfig.initIdentityScope(type);
+
+ noticeBeanDao = new NoticeBeanDao(noticeBeanDaoConfig, this);
+
+ registerDao(NoticeBean.class, noticeBeanDao);
+ }
+
+ public void clear() {
+ noticeBeanDaoConfig.clearIdentityScope();
+ }
+
+ public NoticeBeanDao getNoticeBeanDao() {
+ return noticeBeanDao;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
new file mode 100644
index 0000000..259eb85
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/greendao/NoticeBeanDao.java
@@ -0,0 +1,185 @@
+package com.casic.dcms.greendao;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteStatement;
+
+import org.greenrobot.greendao.AbstractDao;
+import org.greenrobot.greendao.Property;
+import org.greenrobot.greendao.internal.DaoConfig;
+import org.greenrobot.greendao.database.Database;
+import org.greenrobot.greendao.database.DatabaseStatement;
+
+import com.casic.dcms.bean.NoticeBean;
+
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
+/**
+ * DAO for table "NOTICE_BEAN".
+*/
+public class NoticeBeanDao extends AbstractDao {
+
+ public static final String TABLENAME = "NOTICE_BEAN";
+
+ /**
+ * Properties of entity NoticeBean.
+ * Can be used for QueryBuilder and for referencing column names.
+ */
+ public static class Properties {
+ public final static Property Id = new Property(0, Long.class, "id", true, "_id");
+ public final static Property NoticeTitle = new Property(1, String.class, "noticeTitle", false, "NOTICE_TITLE");
+ public final static Property NoticeDate = new Property(2, String.class, "noticeDate", false, "NOTICE_DATE");
+ public final static Property NoticeContent = new Property(3, String.class, "noticeContent", false, "NOTICE_CONTENT");
+ public final static Property SenderName = new Property(4, String.class, "senderName", false, "SENDER_NAME");
+ public final static Property IsRead = new Property(5, String.class, "isRead", false, "IS_READ");
+ }
+
+
+ public NoticeBeanDao(DaoConfig config) {
+ super(config);
+ }
+
+ public NoticeBeanDao(DaoConfig config, DaoSession daoSession) {
+ super(config, daoSession);
+ }
+
+ /** Creates the underlying database table. */
+ public static void createTable(Database db, boolean ifNotExists) {
+ String constraint = ifNotExists? "IF NOT EXISTS ": "";
+ db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_BEAN\" (" + //
+ "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
+ "\"NOTICE_TITLE\" TEXT," + // 1: noticeTitle
+ "\"NOTICE_DATE\" TEXT," + // 2: noticeDate
+ "\"NOTICE_CONTENT\" TEXT," + // 3: noticeContent
+ "\"SENDER_NAME\" TEXT," + // 4: senderName
+ "\"IS_READ\" TEXT);"); // 5: isRead
+ }
+
+ /** Drops the underlying database table. */
+ public static void dropTable(Database db, boolean ifExists) {
+ String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_BEAN\"";
+ db.execSQL(sql);
+ }
+
+ @Override
+ protected final void bindValues(DatabaseStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ protected final void bindValues(SQLiteStatement stmt, NoticeBean entity) {
+ stmt.clearBindings();
+
+ Long id = entity.getId();
+ if (id != null) {
+ stmt.bindLong(1, id);
+ }
+
+ String noticeTitle = entity.getNoticeTitle();
+ if (noticeTitle != null) {
+ stmt.bindString(2, noticeTitle);
+ }
+
+ String noticeDate = entity.getNoticeDate();
+ if (noticeDate != null) {
+ stmt.bindString(3, noticeDate);
+ }
+
+ String noticeContent = entity.getNoticeContent();
+ if (noticeContent != null) {
+ stmt.bindString(4, noticeContent);
+ }
+
+ String senderName = entity.getSenderName();
+ if (senderName != null) {
+ stmt.bindString(5, senderName);
+ }
+
+ String isRead = entity.getIsRead();
+ if (isRead != null) {
+ stmt.bindString(6, isRead);
+ }
+ }
+
+ @Override
+ public Long readKey(Cursor cursor, int offset) {
+ return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
+ }
+
+ @Override
+ public NoticeBean readEntity(Cursor cursor, int offset) {
+ NoticeBean entity = new NoticeBean( //
+ cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
+ cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // noticeTitle
+ cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noticeDate
+ cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // noticeContent
+ cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // senderName
+ cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // isRead
+ );
+ return entity;
+ }
+
+ @Override
+ public void readEntity(Cursor cursor, NoticeBean entity, int offset) {
+ entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
+ entity.setNoticeTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
+ entity.setNoticeDate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
+ entity.setNoticeContent(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
+ entity.setSenderName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
+ entity.setIsRead(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
+ }
+
+ @Override
+ protected final Long updateKeyAfterInsert(NoticeBean entity, long rowId) {
+ entity.setId(rowId);
+ return rowId;
+ }
+
+ @Override
+ public Long getKey(NoticeBean entity) {
+ if(entity != null) {
+ return entity.getId();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean hasKey(NoticeBean entity) {
+ return entity.getId() != null;
+ }
+
+ @Override
+ protected final boolean isEntityUpdateable() {
+ return true;
+ }
+
+}
diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
index 4ff8b3c..10c9d85 100644
--- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
+++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java
@@ -2,6 +2,7 @@
import android.content.Context;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.bean.NoticeBean;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -57,7 +58,11 @@
noticeBean.setSenderName("管理员");
noticeBean.setNoticeDate(TimeOrDateUtil.timestampToDate(System.currentTimeMillis()));
noticeBean.setNoticeContent(msg.getContent());
+ noticeBean.setIsRead("1");
+ //存本地一份
+ BaseApplication.getDaoSession().insert(noticeBean);
+ //发送消息更新界面
BroadcastManager.getInstance(context).sendBroadcast(Constant.NOTICE_MSG, new Gson().toJson(noticeBean));
}
diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
index 1de7445..5f857bc 100644
--- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java
+++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.java
@@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
@@ -19,9 +20,10 @@
import com.casic.dcms.ui.fragment.PhonePageFragment;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
+import com.casic.dcms.utils.StatusBarColorUtil;
import com.casic.dcms.widgets.NoScrollViewPager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
-import com.qmuiteam.qmui.widget.QMUITopBarLayout;
+import com.gyf.immersionbar.ImmersionBar;
import java.util.ArrayList;
import java.util.List;
@@ -31,13 +33,12 @@
public class MainActivity extends DoubleClickExitActivity {
private static final String TAG = "MainActivity";
- @BindView(R.id.mainTopLayout)
- QMUITopBarLayout mainTopLayout;
+ @BindView(R.id.pageTitleView)
+ TextView pageTitleView;
@BindView(R.id.mainViewPager)
NoScrollViewPager mainViewPager;
@BindView(R.id.bottomNavigation)
BottomNavigationView bottomNavigation;
- private Context context = this;
private MenuItem menuItem;
private List pageList;
private BroadcastManager broadcastManager;
@@ -49,8 +50,9 @@
@Override
protected void setupTopBarLayout() {
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
- mainTopLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor));
+ StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor));
+ ImmersionBar.with(this).statusBarDarkFont(false).init();
+ pageTitleView.setText("首页");
}
@Override
@@ -88,19 +90,19 @@
switch (item.getItemId()) {
case R.id.navigation_home:
mainViewPager.setCurrentItem(0);
- mainTopLayout.setTitle("首页").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("首页");
break;
case R.id.navigation_phone:
mainViewPager.setCurrentItem(1);
- mainTopLayout.setTitle("通讯录").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("通讯录");
break;
case R.id.navigation_dashboard:
mainViewPager.setCurrentItem(2);
- mainTopLayout.setTitle("消息").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("消息");
break;
case R.id.navigation_mine:
mainViewPager.setCurrentItem(3);
- mainTopLayout.setTitle("我的").setTextColor(ContextCompat.getColor(context, R.color.white));
+ pageTitleView.setText("我的");
break;
default:
break;
diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
index b8dbeb9..001fb6c 100644
--- a/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
+++ b/app/src/main/java/com/casic/dcms/ui/fragment/UnreadFragment.java
@@ -12,8 +12,10 @@
import com.casic.dcms.R;
import com.casic.dcms.adapter.SwipeViewAdapter;
+import com.casic.dcms.base.BaseApplication;
import com.casic.dcms.base.BaseFragment;
import com.casic.dcms.bean.NoticeBean;
+import com.casic.dcms.greendao.DaoSession;
import com.casic.dcms.ui.NoticeActivity;
import com.casic.dcms.utils.BroadcastManager;
import com.casic.dcms.utils.Constant;
@@ -33,6 +35,7 @@
**/
public class UnreadFragment extends BaseFragment {
+ private static final String TAG = "UnreadFragment";
@BindView(R.id.swipeRecyclerView)
RecyclerView swipeRecyclerView;
@@ -41,6 +44,7 @@
private SwipeViewAdapter swipeViewAdapter;
private BroadcastManager broadcastManager;
private Gson gson;
+ private DaoSession daoSession;
@Override
protected int initLayoutView() {
@@ -55,7 +59,12 @@
@Override
protected void initData() {
gson = new Gson();
- swipeViewAdapter = new SwipeViewAdapter(getContext());
+ daoSession = BaseApplication.getDaoSession();
+ swipeViewAdapter = new SwipeViewAdapter(context);
+ //加载历史数据
+ noticeBeans = daoSession.loadAll(NoticeBean.class);
+ swipeViewAdapter.setData(noticeBeans);
+
broadcastManager = BroadcastManager.getInstance(context);
broadcastManager.addAction(Constant.NOTICE_MSG, new BroadcastReceiver() {
@Override
@@ -67,9 +76,10 @@
assert data != null;
NoticeBean noticeBean = gson.fromJson(data, NoticeBean.class);
noticeBeans.add(noticeBean);
+ //更新数据
+ swipeViewAdapter.setData(noticeBeans);
}
}
- swipeViewAdapter.setData(noticeBeans);
}
});
}
@@ -78,7 +88,9 @@
QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() {
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
- swipeViewAdapter.remove(viewHolder.getAdapterPosition());
+ int position = viewHolder.getAdapterPosition();
+ daoSession.delete(noticeBeans.get(position));
+ swipeViewAdapter.remove(position);
}
@Override
@@ -89,15 +101,16 @@
@Override
public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) {
super.onClickAction(swipeAction, selected, action);
- swipeViewAdapter.remove(selected.getAdapterPosition());
+ int position = selected.getAdapterPosition();
+ daoSession.delete(noticeBeans.get(position));
+ swipeViewAdapter.remove(position);
}
});
swipeAction.attachToRecyclerView(swipeRecyclerView);
swipeRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()) {
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
- return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
+ return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
});
swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
@@ -107,6 +120,9 @@
public void onClick(int position) {
//查看之后,未读消息变为已读消息
NoticeBean noticeBean = noticeBeans.get(position);
+ noticeBean.setIsRead("0");
+ daoSession.update(noticeBean);
+
Intent intent = new Intent(context, NoticeActivity.class);
intent.putExtra("noticeBeanJson", new Gson().toJson(noticeBean));
startActivity(intent);
@@ -117,6 +133,6 @@
@Override
public void onDestroyView() {
super.onDestroyView();
- broadcastManager.destroy(Constant.LOGIN_OUT_ACTION);
+ broadcastManager.destroy(Constant.NOTICE_MSG);
}
}
diff --git a/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java b/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java
new file mode 100644
index 0000000..9e5109c
--- /dev/null
+++ b/app/src/main/java/com/casic/dcms/utils/StatusBarColorUtil.java
@@ -0,0 +1,43 @@
+package com.casic.dcms.utils;
+
+import android.app.Activity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.LinearLayout;
+
+public class StatusBarColorUtil {
+ public static void setColor(Activity activity, int color) {
+ //限制android系统的版本
+ // 设置状态栏透明
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ // 生成一个状态栏大小的矩形
+ View statusView = createStatusView(activity, color);
+ // 添加 statusView 到布局中
+ ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
+ decorView.addView(statusView);
+ // 设置根布局的参数
+ ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
+ rootView.setFitsSystemWindows(true);
+ rootView.setClipToPadding(true);
+ }
+
+ /**
+ * 生成一个和状态栏大小相同的矩形条
+ *
+ * @param activity 需要设置的activity
+ * @param color 状态栏颜色值
+ * @return 状态栏矩形条
+ */
+ private static View createStatusView(Activity activity, int color) {
+ // 获得状态栏高度
+ int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
+ int statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);
+ // 绘制一个和状态栏一样高的矩形
+ View statusView = new View(activity);
+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
+ statusView.setLayoutParams(params);
+ statusView.setBackgroundColor(color);
+ return statusView;
+ }
+}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 45f3e3d..8e25113 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -5,11 +5,16 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
+ android:background="@color/mainThemeColor"
+ android:gravity="center"
+ android:paddingVertical="15dp"
+ android:text="@string/app_name"
+ android:textColor="@color/white"
+ android:textSize="@dimen/titleFontSize" />
+ android:layout_height="wrap_content">