diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt new file mode 100644 index 0000000..a33bb4e --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt @@ -0,0 +1,183 @@ +package com.casic.dcms.ui.fragment + +import android.app.ProgressDialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.casic.dcms.BuildConfig +import com.casic.dcms.R +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.bean.NewVersionBean +import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl +import com.casic.dcms.mvp.presenter.UpdatePresenterImpl +import com.casic.dcms.mvp.view.ILoginOutView +import com.casic.dcms.mvp.view.IUpdateVersionView +import com.casic.dcms.ui.ChangePasswordActivity +import com.casic.dcms.ui.HelpfulActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.ui.UserInfoActivity +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IDownloadListener +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MinePageFragment : BaseFragment(), IUpdateVersionView, ILoginOutView { + + private var clipboardManager: ClipboardManager? = null + private lateinit var loginOutPresenter: LoginOutPresenterImpl + private lateinit var updatePresenter: UpdatePresenterImpl + private lateinit var progressDialog: ProgressDialog + + override fun initLayoutView(): Int = R.layout.fragment_mine + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deviceIdView!!.text = OtherUtils.obtainSimCardSerialNumber(context) + versionCodeView!!.text = BuildConfig.VERSION_NAME + loginOutPresenter = LoginOutPresenterImpl(this) + val isAutoLogin = SaveKeyValues.getValue("autoLogin", false) as Boolean + autoLoginSwitch!!.isChecked = isAutoLogin + updatePresenter = UpdatePresenterImpl(this) + clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + + //下载进度条 + progressDialog = ProgressDialog(context) + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + progressDialog.setProgressDrawable(context?.resources!!.getDrawable(R.drawable.bg_progress)) + progressDialog.setCanceledOnTouchOutside(false) + } + + override fun initEvent() { + userNameLayout.setOnClickListener { + startActivity(Intent(context, UserInfoActivity::class.java)) + } + passwordLayout.setOnClickListener { + startActivity(Intent(context, ChangePasswordActivity::class.java)) + } + helpfulLayout.setOnClickListener { + startActivity(Intent(context, HelpfulActivity::class.java)) + } + autoLoginSwitch!!.setOnCheckedChangeListener { buttonView, isChecked -> + SaveKeyValues.putValue("autoLogin", isChecked) + } + copyView.setOnClickListener { + val clipData = ClipData.newPlainText("deviceId", deviceIdView!!.text.toString()) + clipboardManager!!.setPrimaryClip(clipData) + ToastHelper.showToast("复制成功", ToastHelper.SUCCESS) + } + updateVersionView.setOnClickListener { updatePresenter.onReadyRetrofitRequest() } + + loginOutButton!!.setChangeAlphaWhenPress(true) + loginOutButton.setOnClickListener { + MessageDialogBuilder(context) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + loginOutPresenter.onReadyRetrofitRequest() + }.create().show() + } + } + + override fun obtainLoginOutResult(resultBean: ActionResultBean) { + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + } + + override fun showProgress() { + OtherUtils.showLoadingDialog(context, "请求中,请稍后") + } + + override fun hideProgress() { + OtherUtils.dismissLoadingDialog() + } + + override fun obtainVersionResult(resultBean: NewVersionBean) { +// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val data = resultBean.data + val version = data.version + if (BuildConfig.VERSION_NAME == version) { + ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO) + } else { + val downloadUrl = StringHelper.appendDownloadUrl(data.downloadUrl) + //http://111.198.10.15:11409/static/app/v1.1.0.0.apk + MessageDialogBuilder(context) + .setTitle("版本更新") + .setMessage("确定下载新版本吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定", QMUIDialogAction.ActionListener { dialog, index -> + dialog.dismiss() + //下载新版本 + progressDialog.setMessage("下载新版本中...") + progressDialog.show() + if (progressDialog.progress != 0) { + progressDialog.progress = 0 //防止下载到中途却卡住无法再进行下载 + return@ActionListener + } + downloadApk(downloadUrl) + }).create().show() + } + } + } + + //下载apk + private fun downloadApk(url: String) { + FileUtils.downloadFile(url, object : IDownloadListener { + override fun onDownloadStart(totalBytes: Long) { + progressDialog.max = totalBytes.toInt() + } + + override fun onProgressChanged(currentBytes: Long) { + progressDialog.progress = currentBytes.toInt() + } + + override fun onDownloadEnd(file: File) { + progressDialog.progress = 0 //防止下载完成却卡住的情况 + progressDialog.dismiss() + installApk(file) + } + }) + } + + //安装apk文件 + private fun installApk(apk: File) { + val intent = Intent(Intent.ACTION_VIEW) + val data: Uri + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //判断版本大于等于7.0 + // 通过FileProvider创建一个content类型的Uri + data = FileProvider.getUriForFile( + requireContext(), + "com.casic.dcms.install.fileProvider", apk + ) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 给目标应用一个临时授权 + } else { + data = Uri.fromFile(apk) + } + intent.setDataAndType(data, "application/vnd.android.package-archive") + requireContext().startActivity(intent) + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } + + override fun onDestroyView() { + super.onDestroyView() + loginOutPresenter.disposeRetrofitRequest() + updatePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt new file mode 100644 index 0000000..a33bb4e --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt @@ -0,0 +1,183 @@ +package com.casic.dcms.ui.fragment + +import android.app.ProgressDialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.casic.dcms.BuildConfig +import com.casic.dcms.R +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.bean.NewVersionBean +import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl +import com.casic.dcms.mvp.presenter.UpdatePresenterImpl +import com.casic.dcms.mvp.view.ILoginOutView +import com.casic.dcms.mvp.view.IUpdateVersionView +import com.casic.dcms.ui.ChangePasswordActivity +import com.casic.dcms.ui.HelpfulActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.ui.UserInfoActivity +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IDownloadListener +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MinePageFragment : BaseFragment(), IUpdateVersionView, ILoginOutView { + + private var clipboardManager: ClipboardManager? = null + private lateinit var loginOutPresenter: LoginOutPresenterImpl + private lateinit var updatePresenter: UpdatePresenterImpl + private lateinit var progressDialog: ProgressDialog + + override fun initLayoutView(): Int = R.layout.fragment_mine + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deviceIdView!!.text = OtherUtils.obtainSimCardSerialNumber(context) + versionCodeView!!.text = BuildConfig.VERSION_NAME + loginOutPresenter = LoginOutPresenterImpl(this) + val isAutoLogin = SaveKeyValues.getValue("autoLogin", false) as Boolean + autoLoginSwitch!!.isChecked = isAutoLogin + updatePresenter = UpdatePresenterImpl(this) + clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + + //下载进度条 + progressDialog = ProgressDialog(context) + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + progressDialog.setProgressDrawable(context?.resources!!.getDrawable(R.drawable.bg_progress)) + progressDialog.setCanceledOnTouchOutside(false) + } + + override fun initEvent() { + userNameLayout.setOnClickListener { + startActivity(Intent(context, UserInfoActivity::class.java)) + } + passwordLayout.setOnClickListener { + startActivity(Intent(context, ChangePasswordActivity::class.java)) + } + helpfulLayout.setOnClickListener { + startActivity(Intent(context, HelpfulActivity::class.java)) + } + autoLoginSwitch!!.setOnCheckedChangeListener { buttonView, isChecked -> + SaveKeyValues.putValue("autoLogin", isChecked) + } + copyView.setOnClickListener { + val clipData = ClipData.newPlainText("deviceId", deviceIdView!!.text.toString()) + clipboardManager!!.setPrimaryClip(clipData) + ToastHelper.showToast("复制成功", ToastHelper.SUCCESS) + } + updateVersionView.setOnClickListener { updatePresenter.onReadyRetrofitRequest() } + + loginOutButton!!.setChangeAlphaWhenPress(true) + loginOutButton.setOnClickListener { + MessageDialogBuilder(context) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + loginOutPresenter.onReadyRetrofitRequest() + }.create().show() + } + } + + override fun obtainLoginOutResult(resultBean: ActionResultBean) { + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + } + + override fun showProgress() { + OtherUtils.showLoadingDialog(context, "请求中,请稍后") + } + + override fun hideProgress() { + OtherUtils.dismissLoadingDialog() + } + + override fun obtainVersionResult(resultBean: NewVersionBean) { +// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val data = resultBean.data + val version = data.version + if (BuildConfig.VERSION_NAME == version) { + ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO) + } else { + val downloadUrl = StringHelper.appendDownloadUrl(data.downloadUrl) + //http://111.198.10.15:11409/static/app/v1.1.0.0.apk + MessageDialogBuilder(context) + .setTitle("版本更新") + .setMessage("确定下载新版本吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定", QMUIDialogAction.ActionListener { dialog, index -> + dialog.dismiss() + //下载新版本 + progressDialog.setMessage("下载新版本中...") + progressDialog.show() + if (progressDialog.progress != 0) { + progressDialog.progress = 0 //防止下载到中途却卡住无法再进行下载 + return@ActionListener + } + downloadApk(downloadUrl) + }).create().show() + } + } + } + + //下载apk + private fun downloadApk(url: String) { + FileUtils.downloadFile(url, object : IDownloadListener { + override fun onDownloadStart(totalBytes: Long) { + progressDialog.max = totalBytes.toInt() + } + + override fun onProgressChanged(currentBytes: Long) { + progressDialog.progress = currentBytes.toInt() + } + + override fun onDownloadEnd(file: File) { + progressDialog.progress = 0 //防止下载完成却卡住的情况 + progressDialog.dismiss() + installApk(file) + } + }) + } + + //安装apk文件 + private fun installApk(apk: File) { + val intent = Intent(Intent.ACTION_VIEW) + val data: Uri + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //判断版本大于等于7.0 + // 通过FileProvider创建一个content类型的Uri + data = FileProvider.getUriForFile( + requireContext(), + "com.casic.dcms.install.fileProvider", apk + ) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 给目标应用一个临时授权 + } else { + data = Uri.fromFile(apk) + } + intent.setDataAndType(data, "application/vnd.android.package-archive") + requireContext().startActivity(intent) + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } + + override fun onDestroyView() { + super.onDestroyView() + loginOutPresenter.disposeRetrofitRequest() + updatePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java deleted file mode 100644 index e2488fc..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -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.greendao.NoticeBeanDao; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.igexin.sdk.message.GTTransmitMessage; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; - -import org.jetbrains.annotations.NotNull; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class NoticePageFragment extends BaseFragment { - - private static final String TAG = "NoticePageFragment"; - @BindView(R.id.swipeRecyclerView) - RecyclerView swipeRecyclerView; - - private Context context; - private List noticeBeans = new ArrayList<>(); - private SwipeViewAdapter swipeViewAdapter; - private DaoSession daoSession; - private static WeakReferenceHandler weakReferenceHandler; - - @Override - protected int initLayoutView() { - return R.layout.fragment_notice; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - daoSession = BaseApplication.getDaoSession(); - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeans = daoSession.queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeBeanDao.Properties.PushDate)//按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - - weakReferenceHandler = new WeakReferenceHandler(this); - } - - @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - int position = viewHolder.getAdapterPosition(); - daoSession.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - 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); - } - }); - swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - daoSession.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - - @Override - public void handleMessage(@NotNull Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == Constant.PUSH_MESSAGE_DATA) { - NoticeBean noticeBean = (NoticeBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean);//新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - } -} diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt new file mode 100644 index 0000000..a33bb4e --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt @@ -0,0 +1,183 @@ +package com.casic.dcms.ui.fragment + +import android.app.ProgressDialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.casic.dcms.BuildConfig +import com.casic.dcms.R +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.bean.NewVersionBean +import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl +import com.casic.dcms.mvp.presenter.UpdatePresenterImpl +import com.casic.dcms.mvp.view.ILoginOutView +import com.casic.dcms.mvp.view.IUpdateVersionView +import com.casic.dcms.ui.ChangePasswordActivity +import com.casic.dcms.ui.HelpfulActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.ui.UserInfoActivity +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IDownloadListener +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MinePageFragment : BaseFragment(), IUpdateVersionView, ILoginOutView { + + private var clipboardManager: ClipboardManager? = null + private lateinit var loginOutPresenter: LoginOutPresenterImpl + private lateinit var updatePresenter: UpdatePresenterImpl + private lateinit var progressDialog: ProgressDialog + + override fun initLayoutView(): Int = R.layout.fragment_mine + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deviceIdView!!.text = OtherUtils.obtainSimCardSerialNumber(context) + versionCodeView!!.text = BuildConfig.VERSION_NAME + loginOutPresenter = LoginOutPresenterImpl(this) + val isAutoLogin = SaveKeyValues.getValue("autoLogin", false) as Boolean + autoLoginSwitch!!.isChecked = isAutoLogin + updatePresenter = UpdatePresenterImpl(this) + clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + + //下载进度条 + progressDialog = ProgressDialog(context) + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + progressDialog.setProgressDrawable(context?.resources!!.getDrawable(R.drawable.bg_progress)) + progressDialog.setCanceledOnTouchOutside(false) + } + + override fun initEvent() { + userNameLayout.setOnClickListener { + startActivity(Intent(context, UserInfoActivity::class.java)) + } + passwordLayout.setOnClickListener { + startActivity(Intent(context, ChangePasswordActivity::class.java)) + } + helpfulLayout.setOnClickListener { + startActivity(Intent(context, HelpfulActivity::class.java)) + } + autoLoginSwitch!!.setOnCheckedChangeListener { buttonView, isChecked -> + SaveKeyValues.putValue("autoLogin", isChecked) + } + copyView.setOnClickListener { + val clipData = ClipData.newPlainText("deviceId", deviceIdView!!.text.toString()) + clipboardManager!!.setPrimaryClip(clipData) + ToastHelper.showToast("复制成功", ToastHelper.SUCCESS) + } + updateVersionView.setOnClickListener { updatePresenter.onReadyRetrofitRequest() } + + loginOutButton!!.setChangeAlphaWhenPress(true) + loginOutButton.setOnClickListener { + MessageDialogBuilder(context) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + loginOutPresenter.onReadyRetrofitRequest() + }.create().show() + } + } + + override fun obtainLoginOutResult(resultBean: ActionResultBean) { + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + } + + override fun showProgress() { + OtherUtils.showLoadingDialog(context, "请求中,请稍后") + } + + override fun hideProgress() { + OtherUtils.dismissLoadingDialog() + } + + override fun obtainVersionResult(resultBean: NewVersionBean) { +// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val data = resultBean.data + val version = data.version + if (BuildConfig.VERSION_NAME == version) { + ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO) + } else { + val downloadUrl = StringHelper.appendDownloadUrl(data.downloadUrl) + //http://111.198.10.15:11409/static/app/v1.1.0.0.apk + MessageDialogBuilder(context) + .setTitle("版本更新") + .setMessage("确定下载新版本吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定", QMUIDialogAction.ActionListener { dialog, index -> + dialog.dismiss() + //下载新版本 + progressDialog.setMessage("下载新版本中...") + progressDialog.show() + if (progressDialog.progress != 0) { + progressDialog.progress = 0 //防止下载到中途却卡住无法再进行下载 + return@ActionListener + } + downloadApk(downloadUrl) + }).create().show() + } + } + } + + //下载apk + private fun downloadApk(url: String) { + FileUtils.downloadFile(url, object : IDownloadListener { + override fun onDownloadStart(totalBytes: Long) { + progressDialog.max = totalBytes.toInt() + } + + override fun onProgressChanged(currentBytes: Long) { + progressDialog.progress = currentBytes.toInt() + } + + override fun onDownloadEnd(file: File) { + progressDialog.progress = 0 //防止下载完成却卡住的情况 + progressDialog.dismiss() + installApk(file) + } + }) + } + + //安装apk文件 + private fun installApk(apk: File) { + val intent = Intent(Intent.ACTION_VIEW) + val data: Uri + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //判断版本大于等于7.0 + // 通过FileProvider创建一个content类型的Uri + data = FileProvider.getUriForFile( + requireContext(), + "com.casic.dcms.install.fileProvider", apk + ) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 给目标应用一个临时授权 + } else { + data = Uri.fromFile(apk) + } + intent.setDataAndType(data, "application/vnd.android.package-archive") + requireContext().startActivity(intent) + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } + + override fun onDestroyView() { + super.onDestroyView() + loginOutPresenter.disposeRetrofitRequest() + updatePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java deleted file mode 100644 index e2488fc..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -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.greendao.NoticeBeanDao; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.igexin.sdk.message.GTTransmitMessage; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; - -import org.jetbrains.annotations.NotNull; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class NoticePageFragment extends BaseFragment { - - private static final String TAG = "NoticePageFragment"; - @BindView(R.id.swipeRecyclerView) - RecyclerView swipeRecyclerView; - - private Context context; - private List noticeBeans = new ArrayList<>(); - private SwipeViewAdapter swipeViewAdapter; - private DaoSession daoSession; - private static WeakReferenceHandler weakReferenceHandler; - - @Override - protected int initLayoutView() { - return R.layout.fragment_notice; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - daoSession = BaseApplication.getDaoSession(); - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeans = daoSession.queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeBeanDao.Properties.PushDate)//按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - - weakReferenceHandler = new WeakReferenceHandler(this); - } - - @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - int position = viewHolder.getAdapterPosition(); - daoSession.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - 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); - } - }); - swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - daoSession.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - - @Override - public void handleMessage(@NotNull Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == Constant.PUSH_MESSAGE_DATA) { - NoticeBean noticeBean = (NoticeBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean);//新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt new file mode 100644 index 0000000..05e6ddb --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt @@ -0,0 +1,152 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.os.Handler +import android.os.Message +import android.text.TextUtils +import android.util.Log +import android.view.ViewGroup +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +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.NoticeBeanDao +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction +import com.qmuiteam.qmui.recyclerView.QMUISwipeAction +import kotlinx.android.synthetic.main.fragment_notice.* +import java.lang.ref.WeakReference +import java.util.* + +class NoticePageFragment : BaseFragment() { + + private lateinit var noticeBeanDao: NoticeBeanDao + private lateinit var swipeViewAdapter: SwipeViewAdapter + private var noticeBeans: MutableList = ArrayList() + + override fun initLayoutView(): Int = R.layout.fragment_notice + + override fun setupTopBarLayout() { + + } + + override fun initData() { + swipeViewAdapter = SwipeViewAdapter(context) + //根据loginName加载历史数据 + val account = StringHelper.getUserAccount() + if (TextUtils.isEmpty(account)) { + return + } + noticeBeanDao = BaseApplication.getDaoSession().noticeBeanDao + noticeBeans = noticeBeanDao.queryBuilder() + .where(NoticeBeanDao.Properties.UserAccount.eq(account)) + .orderDesc(NoticeBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 + .list() + swipeViewAdapter.setData(noticeBeans) + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initEvent() { + val swipeAction = QMUIRVItemSwipeAction(true, object : QMUIRVItemSwipeAction.Callback() { + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = viewHolder.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + + override fun getSwipeDirection( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ): Int { + return QMUIRVItemSwipeAction.SWIPE_LEFT + } + + override fun onClickAction( + swipeAction: QMUIRVItemSwipeAction, + selected: RecyclerView.ViewHolder, + action: QMUISwipeAction + ) { + super.onClickAction(swipeAction, selected, action) + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = selected.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + }) + swipeAction.attachToRecyclerView(swipeRecyclerView) + swipeRecyclerView!!.layoutManager = object : LinearLayoutManager(context) { + override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams { + return RecyclerView.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + } + swipeRecyclerView!!.addItemDecoration( + DividerItemDecoration( + context, + DividerItemDecoration.VERTICAL + ) + ) + swipeRecyclerView!!.adapter = swipeViewAdapter + swipeViewAdapter.setOnItemClickListener { position -> //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + + //点击之后之后,未读消息变为已读消息 + val noticeBean = noticeBeans[position] + noticeBean.isRead = "0" + noticeBeanDao.update(noticeBean) + swipeViewAdapter.notifyDataSetChanged() + val caseId = noticeBeans[position].caseId + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + } + + private class WeakReferenceHandler(fragment: NoticePageFragment) : Handler() { + private val reference: WeakReference = WeakReference(fragment) + override fun handleMessage(msg: Message) { + val noticePageFragment: NoticePageFragment? + try { + noticePageFragment = reference.get() + val noticeBeans = noticePageFragment!!.noticeBeans + if (msg.what == Constant.PUSH_MESSAGE_DATA) { + val noticeBean = msg.obj as NoticeBean + Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.caseId) + noticeBeans.add(0, noticeBean) //新消息永远放到第一个 + //更新数据 + noticePageFragment.swipeViewAdapter.setData(noticeBeans) + } + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + + } + + companion object { + private const val TAG = "NoticePageFragment" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + } +} \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt new file mode 100644 index 0000000..a33bb4e --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt @@ -0,0 +1,183 @@ +package com.casic.dcms.ui.fragment + +import android.app.ProgressDialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.casic.dcms.BuildConfig +import com.casic.dcms.R +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.bean.NewVersionBean +import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl +import com.casic.dcms.mvp.presenter.UpdatePresenterImpl +import com.casic.dcms.mvp.view.ILoginOutView +import com.casic.dcms.mvp.view.IUpdateVersionView +import com.casic.dcms.ui.ChangePasswordActivity +import com.casic.dcms.ui.HelpfulActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.ui.UserInfoActivity +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IDownloadListener +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MinePageFragment : BaseFragment(), IUpdateVersionView, ILoginOutView { + + private var clipboardManager: ClipboardManager? = null + private lateinit var loginOutPresenter: LoginOutPresenterImpl + private lateinit var updatePresenter: UpdatePresenterImpl + private lateinit var progressDialog: ProgressDialog + + override fun initLayoutView(): Int = R.layout.fragment_mine + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deviceIdView!!.text = OtherUtils.obtainSimCardSerialNumber(context) + versionCodeView!!.text = BuildConfig.VERSION_NAME + loginOutPresenter = LoginOutPresenterImpl(this) + val isAutoLogin = SaveKeyValues.getValue("autoLogin", false) as Boolean + autoLoginSwitch!!.isChecked = isAutoLogin + updatePresenter = UpdatePresenterImpl(this) + clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + + //下载进度条 + progressDialog = ProgressDialog(context) + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + progressDialog.setProgressDrawable(context?.resources!!.getDrawable(R.drawable.bg_progress)) + progressDialog.setCanceledOnTouchOutside(false) + } + + override fun initEvent() { + userNameLayout.setOnClickListener { + startActivity(Intent(context, UserInfoActivity::class.java)) + } + passwordLayout.setOnClickListener { + startActivity(Intent(context, ChangePasswordActivity::class.java)) + } + helpfulLayout.setOnClickListener { + startActivity(Intent(context, HelpfulActivity::class.java)) + } + autoLoginSwitch!!.setOnCheckedChangeListener { buttonView, isChecked -> + SaveKeyValues.putValue("autoLogin", isChecked) + } + copyView.setOnClickListener { + val clipData = ClipData.newPlainText("deviceId", deviceIdView!!.text.toString()) + clipboardManager!!.setPrimaryClip(clipData) + ToastHelper.showToast("复制成功", ToastHelper.SUCCESS) + } + updateVersionView.setOnClickListener { updatePresenter.onReadyRetrofitRequest() } + + loginOutButton!!.setChangeAlphaWhenPress(true) + loginOutButton.setOnClickListener { + MessageDialogBuilder(context) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + loginOutPresenter.onReadyRetrofitRequest() + }.create().show() + } + } + + override fun obtainLoginOutResult(resultBean: ActionResultBean) { + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + } + + override fun showProgress() { + OtherUtils.showLoadingDialog(context, "请求中,请稍后") + } + + override fun hideProgress() { + OtherUtils.dismissLoadingDialog() + } + + override fun obtainVersionResult(resultBean: NewVersionBean) { +// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val data = resultBean.data + val version = data.version + if (BuildConfig.VERSION_NAME == version) { + ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO) + } else { + val downloadUrl = StringHelper.appendDownloadUrl(data.downloadUrl) + //http://111.198.10.15:11409/static/app/v1.1.0.0.apk + MessageDialogBuilder(context) + .setTitle("版本更新") + .setMessage("确定下载新版本吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定", QMUIDialogAction.ActionListener { dialog, index -> + dialog.dismiss() + //下载新版本 + progressDialog.setMessage("下载新版本中...") + progressDialog.show() + if (progressDialog.progress != 0) { + progressDialog.progress = 0 //防止下载到中途却卡住无法再进行下载 + return@ActionListener + } + downloadApk(downloadUrl) + }).create().show() + } + } + } + + //下载apk + private fun downloadApk(url: String) { + FileUtils.downloadFile(url, object : IDownloadListener { + override fun onDownloadStart(totalBytes: Long) { + progressDialog.max = totalBytes.toInt() + } + + override fun onProgressChanged(currentBytes: Long) { + progressDialog.progress = currentBytes.toInt() + } + + override fun onDownloadEnd(file: File) { + progressDialog.progress = 0 //防止下载完成却卡住的情况 + progressDialog.dismiss() + installApk(file) + } + }) + } + + //安装apk文件 + private fun installApk(apk: File) { + val intent = Intent(Intent.ACTION_VIEW) + val data: Uri + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //判断版本大于等于7.0 + // 通过FileProvider创建一个content类型的Uri + data = FileProvider.getUriForFile( + requireContext(), + "com.casic.dcms.install.fileProvider", apk + ) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 给目标应用一个临时授权 + } else { + data = Uri.fromFile(apk) + } + intent.setDataAndType(data, "application/vnd.android.package-archive") + requireContext().startActivity(intent) + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } + + override fun onDestroyView() { + super.onDestroyView() + loginOutPresenter.disposeRetrofitRequest() + updatePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java deleted file mode 100644 index e2488fc..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -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.greendao.NoticeBeanDao; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.igexin.sdk.message.GTTransmitMessage; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; - -import org.jetbrains.annotations.NotNull; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class NoticePageFragment extends BaseFragment { - - private static final String TAG = "NoticePageFragment"; - @BindView(R.id.swipeRecyclerView) - RecyclerView swipeRecyclerView; - - private Context context; - private List noticeBeans = new ArrayList<>(); - private SwipeViewAdapter swipeViewAdapter; - private DaoSession daoSession; - private static WeakReferenceHandler weakReferenceHandler; - - @Override - protected int initLayoutView() { - return R.layout.fragment_notice; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - daoSession = BaseApplication.getDaoSession(); - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeans = daoSession.queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeBeanDao.Properties.PushDate)//按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - - weakReferenceHandler = new WeakReferenceHandler(this); - } - - @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - int position = viewHolder.getAdapterPosition(); - daoSession.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - 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); - } - }); - swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - daoSession.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - - @Override - public void handleMessage(@NotNull Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == Constant.PUSH_MESSAGE_DATA) { - NoticeBean noticeBean = (NoticeBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean);//新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt new file mode 100644 index 0000000..05e6ddb --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt @@ -0,0 +1,152 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.os.Handler +import android.os.Message +import android.text.TextUtils +import android.util.Log +import android.view.ViewGroup +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +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.NoticeBeanDao +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction +import com.qmuiteam.qmui.recyclerView.QMUISwipeAction +import kotlinx.android.synthetic.main.fragment_notice.* +import java.lang.ref.WeakReference +import java.util.* + +class NoticePageFragment : BaseFragment() { + + private lateinit var noticeBeanDao: NoticeBeanDao + private lateinit var swipeViewAdapter: SwipeViewAdapter + private var noticeBeans: MutableList = ArrayList() + + override fun initLayoutView(): Int = R.layout.fragment_notice + + override fun setupTopBarLayout() { + + } + + override fun initData() { + swipeViewAdapter = SwipeViewAdapter(context) + //根据loginName加载历史数据 + val account = StringHelper.getUserAccount() + if (TextUtils.isEmpty(account)) { + return + } + noticeBeanDao = BaseApplication.getDaoSession().noticeBeanDao + noticeBeans = noticeBeanDao.queryBuilder() + .where(NoticeBeanDao.Properties.UserAccount.eq(account)) + .orderDesc(NoticeBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 + .list() + swipeViewAdapter.setData(noticeBeans) + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initEvent() { + val swipeAction = QMUIRVItemSwipeAction(true, object : QMUIRVItemSwipeAction.Callback() { + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = viewHolder.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + + override fun getSwipeDirection( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ): Int { + return QMUIRVItemSwipeAction.SWIPE_LEFT + } + + override fun onClickAction( + swipeAction: QMUIRVItemSwipeAction, + selected: RecyclerView.ViewHolder, + action: QMUISwipeAction + ) { + super.onClickAction(swipeAction, selected, action) + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = selected.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + }) + swipeAction.attachToRecyclerView(swipeRecyclerView) + swipeRecyclerView!!.layoutManager = object : LinearLayoutManager(context) { + override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams { + return RecyclerView.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + } + swipeRecyclerView!!.addItemDecoration( + DividerItemDecoration( + context, + DividerItemDecoration.VERTICAL + ) + ) + swipeRecyclerView!!.adapter = swipeViewAdapter + swipeViewAdapter.setOnItemClickListener { position -> //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + + //点击之后之后,未读消息变为已读消息 + val noticeBean = noticeBeans[position] + noticeBean.isRead = "0" + noticeBeanDao.update(noticeBean) + swipeViewAdapter.notifyDataSetChanged() + val caseId = noticeBeans[position].caseId + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + } + + private class WeakReferenceHandler(fragment: NoticePageFragment) : Handler() { + private val reference: WeakReference = WeakReference(fragment) + override fun handleMessage(msg: Message) { + val noticePageFragment: NoticePageFragment? + try { + noticePageFragment = reference.get() + val noticeBeans = noticePageFragment!!.noticeBeans + if (msg.what == Constant.PUSH_MESSAGE_DATA) { + val noticeBean = msg.obj as NoticeBean + Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.caseId) + noticeBeans.add(0, noticeBean) //新消息永远放到第一个 + //更新数据 + noticePageFragment.swipeViewAdapter.setData(noticeBeans) + } + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + + } + + companion object { + private const val TAG = "NoticePageFragment" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java deleted file mode 100644 index 13aa09b..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.text.TextUtils; -import android.view.View; -import android.widget.ExpandableListView; - -import com.casic.dcms.R; -import com.casic.dcms.adapter.DeptExpandableAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.DeptTreeBean; -import com.casic.dcms.bean.PersonBean; -import com.casic.dcms.bean.PhoneBookBean; -import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl; -import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl; -import com.casic.dcms.mvp.view.IDeptTreeView; -import com.casic.dcms.mvp.view.IPhoneBookView; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; - -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class PhonePageFragment extends BaseFragment implements IDeptTreeView, IPhoneBookView { - - private static final String TAG = "PhonePageFragment"; - - @BindView(R.id.deptTreeView) - ExpandableListView deptTreeView; - - private Context context; - private DeptTreePresenterImpl deptTreePresenter; - private PhoneBookPresenterImpl phoneBookPresenter; - private List deptList = new ArrayList<>();//部门名集合 - private List> deptAndPersons = new ArrayList<>();//个人信息集合的集合 - private DeptExpandableAdapter expandableAdapter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_phone; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deptTreePresenter = new DeptTreePresenterImpl(this); - deptTreePresenter.onReadyRetrofitRequest("0"); - phoneBookPresenter = new PhoneBookPresenterImpl(this); - expandableAdapter = new DeptExpandableAdapter(context); - } - - @Override - protected void initEvent() { - - } - - - @Override - public void obtainDeptTreeResult(DeptTreeBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - //先获取部门树,在往树结构里面加人 - if (resultBean.isSuccess()) { - List listBeans = resultBean.getData().getList(); - deptList.clear(); - for (DeptTreeBean.DataBean.ListBean bean : listBeans) { - deptList.add(bean.getName()); - } - if (deptList.size() > 0) { - phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().getDeptId()); - } - } - } - - @Override - public void obtainPhoneBookResult(PhoneBookBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - List dataBeans = resultBean.getData(); - deptAndPersons.clear(); - for (String title : deptList) { - List beanList = new ArrayList<>(); - for (PhoneBookBean.DataBean dataBean : dataBeans) { - if (title.equals(dataBean.getDeptName())) { - PersonBean personBean = new PersonBean(); - personBean.setPersonDept(dataBean.getDeptName()); - personBean.setPersonName(dataBean.getName()); - personBean.setPersonPhone(dataBean.getPhone()); - - beanList.add(personBean); - } - } - deptAndPersons.add(beanList); - } - //展示部门树以及人员 - expandableAdapter.setData(deptList, deptAndPersons); - deptTreeView.setAdapter(expandableAdapter); - //默认展开数据 - for (int i = 0; i < expandableAdapter.getGroupCount(); i++) { - deptTreeView.expandGroup(i); - } - deptTreeView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { - @Override - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - PersonBean personBean = deptAndPersons.get(groupPosition).get(childPosition); - callPhone(personBean.getPersonName(), personBean.getPersonPhone()); - return true; - } - }); - } - } - - /** - * 直接呼叫电话 - */ - private void callPhone(String personName, String personPhone) { - if (TextUtils.isEmpty(personPhone)) { - ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR); - return; - } - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("提示") - .setMessage("是否确定拨打[" + personName + "]的电话?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_CALL); - intent.setData(Uri.parse("tel:" + personPhone)); - startActivity(intent); - } - }) - .create().show(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (deptTreePresenter != null) { - deptTreePresenter.disposeRetrofitRequest(); - } - if (phoneBookPresenter != null) { - phoneBookPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt new file mode 100644 index 0000000..a33bb4e --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt @@ -0,0 +1,183 @@ +package com.casic.dcms.ui.fragment + +import android.app.ProgressDialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.casic.dcms.BuildConfig +import com.casic.dcms.R +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.bean.NewVersionBean +import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl +import com.casic.dcms.mvp.presenter.UpdatePresenterImpl +import com.casic.dcms.mvp.view.ILoginOutView +import com.casic.dcms.mvp.view.IUpdateVersionView +import com.casic.dcms.ui.ChangePasswordActivity +import com.casic.dcms.ui.HelpfulActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.ui.UserInfoActivity +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IDownloadListener +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MinePageFragment : BaseFragment(), IUpdateVersionView, ILoginOutView { + + private var clipboardManager: ClipboardManager? = null + private lateinit var loginOutPresenter: LoginOutPresenterImpl + private lateinit var updatePresenter: UpdatePresenterImpl + private lateinit var progressDialog: ProgressDialog + + override fun initLayoutView(): Int = R.layout.fragment_mine + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deviceIdView!!.text = OtherUtils.obtainSimCardSerialNumber(context) + versionCodeView!!.text = BuildConfig.VERSION_NAME + loginOutPresenter = LoginOutPresenterImpl(this) + val isAutoLogin = SaveKeyValues.getValue("autoLogin", false) as Boolean + autoLoginSwitch!!.isChecked = isAutoLogin + updatePresenter = UpdatePresenterImpl(this) + clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + + //下载进度条 + progressDialog = ProgressDialog(context) + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + progressDialog.setProgressDrawable(context?.resources!!.getDrawable(R.drawable.bg_progress)) + progressDialog.setCanceledOnTouchOutside(false) + } + + override fun initEvent() { + userNameLayout.setOnClickListener { + startActivity(Intent(context, UserInfoActivity::class.java)) + } + passwordLayout.setOnClickListener { + startActivity(Intent(context, ChangePasswordActivity::class.java)) + } + helpfulLayout.setOnClickListener { + startActivity(Intent(context, HelpfulActivity::class.java)) + } + autoLoginSwitch!!.setOnCheckedChangeListener { buttonView, isChecked -> + SaveKeyValues.putValue("autoLogin", isChecked) + } + copyView.setOnClickListener { + val clipData = ClipData.newPlainText("deviceId", deviceIdView!!.text.toString()) + clipboardManager!!.setPrimaryClip(clipData) + ToastHelper.showToast("复制成功", ToastHelper.SUCCESS) + } + updateVersionView.setOnClickListener { updatePresenter.onReadyRetrofitRequest() } + + loginOutButton!!.setChangeAlphaWhenPress(true) + loginOutButton.setOnClickListener { + MessageDialogBuilder(context) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + loginOutPresenter.onReadyRetrofitRequest() + }.create().show() + } + } + + override fun obtainLoginOutResult(resultBean: ActionResultBean) { + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + } + + override fun showProgress() { + OtherUtils.showLoadingDialog(context, "请求中,请稍后") + } + + override fun hideProgress() { + OtherUtils.dismissLoadingDialog() + } + + override fun obtainVersionResult(resultBean: NewVersionBean) { +// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val data = resultBean.data + val version = data.version + if (BuildConfig.VERSION_NAME == version) { + ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO) + } else { + val downloadUrl = StringHelper.appendDownloadUrl(data.downloadUrl) + //http://111.198.10.15:11409/static/app/v1.1.0.0.apk + MessageDialogBuilder(context) + .setTitle("版本更新") + .setMessage("确定下载新版本吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定", QMUIDialogAction.ActionListener { dialog, index -> + dialog.dismiss() + //下载新版本 + progressDialog.setMessage("下载新版本中...") + progressDialog.show() + if (progressDialog.progress != 0) { + progressDialog.progress = 0 //防止下载到中途却卡住无法再进行下载 + return@ActionListener + } + downloadApk(downloadUrl) + }).create().show() + } + } + } + + //下载apk + private fun downloadApk(url: String) { + FileUtils.downloadFile(url, object : IDownloadListener { + override fun onDownloadStart(totalBytes: Long) { + progressDialog.max = totalBytes.toInt() + } + + override fun onProgressChanged(currentBytes: Long) { + progressDialog.progress = currentBytes.toInt() + } + + override fun onDownloadEnd(file: File) { + progressDialog.progress = 0 //防止下载完成却卡住的情况 + progressDialog.dismiss() + installApk(file) + } + }) + } + + //安装apk文件 + private fun installApk(apk: File) { + val intent = Intent(Intent.ACTION_VIEW) + val data: Uri + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //判断版本大于等于7.0 + // 通过FileProvider创建一个content类型的Uri + data = FileProvider.getUriForFile( + requireContext(), + "com.casic.dcms.install.fileProvider", apk + ) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 给目标应用一个临时授权 + } else { + data = Uri.fromFile(apk) + } + intent.setDataAndType(data, "application/vnd.android.package-archive") + requireContext().startActivity(intent) + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } + + override fun onDestroyView() { + super.onDestroyView() + loginOutPresenter.disposeRetrofitRequest() + updatePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java deleted file mode 100644 index e2488fc..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -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.greendao.NoticeBeanDao; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.igexin.sdk.message.GTTransmitMessage; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; - -import org.jetbrains.annotations.NotNull; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class NoticePageFragment extends BaseFragment { - - private static final String TAG = "NoticePageFragment"; - @BindView(R.id.swipeRecyclerView) - RecyclerView swipeRecyclerView; - - private Context context; - private List noticeBeans = new ArrayList<>(); - private SwipeViewAdapter swipeViewAdapter; - private DaoSession daoSession; - private static WeakReferenceHandler weakReferenceHandler; - - @Override - protected int initLayoutView() { - return R.layout.fragment_notice; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - daoSession = BaseApplication.getDaoSession(); - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeans = daoSession.queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeBeanDao.Properties.PushDate)//按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - - weakReferenceHandler = new WeakReferenceHandler(this); - } - - @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - int position = viewHolder.getAdapterPosition(); - daoSession.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - 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); - } - }); - swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - daoSession.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - - @Override - public void handleMessage(@NotNull Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == Constant.PUSH_MESSAGE_DATA) { - NoticeBean noticeBean = (NoticeBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean);//新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt new file mode 100644 index 0000000..05e6ddb --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt @@ -0,0 +1,152 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.os.Handler +import android.os.Message +import android.text.TextUtils +import android.util.Log +import android.view.ViewGroup +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +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.NoticeBeanDao +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction +import com.qmuiteam.qmui.recyclerView.QMUISwipeAction +import kotlinx.android.synthetic.main.fragment_notice.* +import java.lang.ref.WeakReference +import java.util.* + +class NoticePageFragment : BaseFragment() { + + private lateinit var noticeBeanDao: NoticeBeanDao + private lateinit var swipeViewAdapter: SwipeViewAdapter + private var noticeBeans: MutableList = ArrayList() + + override fun initLayoutView(): Int = R.layout.fragment_notice + + override fun setupTopBarLayout() { + + } + + override fun initData() { + swipeViewAdapter = SwipeViewAdapter(context) + //根据loginName加载历史数据 + val account = StringHelper.getUserAccount() + if (TextUtils.isEmpty(account)) { + return + } + noticeBeanDao = BaseApplication.getDaoSession().noticeBeanDao + noticeBeans = noticeBeanDao.queryBuilder() + .where(NoticeBeanDao.Properties.UserAccount.eq(account)) + .orderDesc(NoticeBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 + .list() + swipeViewAdapter.setData(noticeBeans) + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initEvent() { + val swipeAction = QMUIRVItemSwipeAction(true, object : QMUIRVItemSwipeAction.Callback() { + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = viewHolder.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + + override fun getSwipeDirection( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ): Int { + return QMUIRVItemSwipeAction.SWIPE_LEFT + } + + override fun onClickAction( + swipeAction: QMUIRVItemSwipeAction, + selected: RecyclerView.ViewHolder, + action: QMUISwipeAction + ) { + super.onClickAction(swipeAction, selected, action) + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = selected.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + }) + swipeAction.attachToRecyclerView(swipeRecyclerView) + swipeRecyclerView!!.layoutManager = object : LinearLayoutManager(context) { + override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams { + return RecyclerView.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + } + swipeRecyclerView!!.addItemDecoration( + DividerItemDecoration( + context, + DividerItemDecoration.VERTICAL + ) + ) + swipeRecyclerView!!.adapter = swipeViewAdapter + swipeViewAdapter.setOnItemClickListener { position -> //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + + //点击之后之后,未读消息变为已读消息 + val noticeBean = noticeBeans[position] + noticeBean.isRead = "0" + noticeBeanDao.update(noticeBean) + swipeViewAdapter.notifyDataSetChanged() + val caseId = noticeBeans[position].caseId + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + } + + private class WeakReferenceHandler(fragment: NoticePageFragment) : Handler() { + private val reference: WeakReference = WeakReference(fragment) + override fun handleMessage(msg: Message) { + val noticePageFragment: NoticePageFragment? + try { + noticePageFragment = reference.get() + val noticeBeans = noticePageFragment!!.noticeBeans + if (msg.what == Constant.PUSH_MESSAGE_DATA) { + val noticeBean = msg.obj as NoticeBean + Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.caseId) + noticeBeans.add(0, noticeBean) //新消息永远放到第一个 + //更新数据 + noticePageFragment.swipeViewAdapter.setData(noticeBeans) + } + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + + } + + companion object { + private const val TAG = "NoticePageFragment" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java deleted file mode 100644 index 13aa09b..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.text.TextUtils; -import android.view.View; -import android.widget.ExpandableListView; - -import com.casic.dcms.R; -import com.casic.dcms.adapter.DeptExpandableAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.DeptTreeBean; -import com.casic.dcms.bean.PersonBean; -import com.casic.dcms.bean.PhoneBookBean; -import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl; -import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl; -import com.casic.dcms.mvp.view.IDeptTreeView; -import com.casic.dcms.mvp.view.IPhoneBookView; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; - -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class PhonePageFragment extends BaseFragment implements IDeptTreeView, IPhoneBookView { - - private static final String TAG = "PhonePageFragment"; - - @BindView(R.id.deptTreeView) - ExpandableListView deptTreeView; - - private Context context; - private DeptTreePresenterImpl deptTreePresenter; - private PhoneBookPresenterImpl phoneBookPresenter; - private List deptList = new ArrayList<>();//部门名集合 - private List> deptAndPersons = new ArrayList<>();//个人信息集合的集合 - private DeptExpandableAdapter expandableAdapter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_phone; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deptTreePresenter = new DeptTreePresenterImpl(this); - deptTreePresenter.onReadyRetrofitRequest("0"); - phoneBookPresenter = new PhoneBookPresenterImpl(this); - expandableAdapter = new DeptExpandableAdapter(context); - } - - @Override - protected void initEvent() { - - } - - - @Override - public void obtainDeptTreeResult(DeptTreeBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - //先获取部门树,在往树结构里面加人 - if (resultBean.isSuccess()) { - List listBeans = resultBean.getData().getList(); - deptList.clear(); - for (DeptTreeBean.DataBean.ListBean bean : listBeans) { - deptList.add(bean.getName()); - } - if (deptList.size() > 0) { - phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().getDeptId()); - } - } - } - - @Override - public void obtainPhoneBookResult(PhoneBookBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - List dataBeans = resultBean.getData(); - deptAndPersons.clear(); - for (String title : deptList) { - List beanList = new ArrayList<>(); - for (PhoneBookBean.DataBean dataBean : dataBeans) { - if (title.equals(dataBean.getDeptName())) { - PersonBean personBean = new PersonBean(); - personBean.setPersonDept(dataBean.getDeptName()); - personBean.setPersonName(dataBean.getName()); - personBean.setPersonPhone(dataBean.getPhone()); - - beanList.add(personBean); - } - } - deptAndPersons.add(beanList); - } - //展示部门树以及人员 - expandableAdapter.setData(deptList, deptAndPersons); - deptTreeView.setAdapter(expandableAdapter); - //默认展开数据 - for (int i = 0; i < expandableAdapter.getGroupCount(); i++) { - deptTreeView.expandGroup(i); - } - deptTreeView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { - @Override - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - PersonBean personBean = deptAndPersons.get(groupPosition).get(childPosition); - callPhone(personBean.getPersonName(), personBean.getPersonPhone()); - return true; - } - }); - } - } - - /** - * 直接呼叫电话 - */ - private void callPhone(String personName, String personPhone) { - if (TextUtils.isEmpty(personPhone)) { - ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR); - return; - } - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("提示") - .setMessage("是否确定拨打[" + personName + "]的电话?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_CALL); - intent.setData(Uri.parse("tel:" + personPhone)); - startActivity(intent); - } - }) - .create().show(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (deptTreePresenter != null) { - deptTreePresenter.disposeRetrofitRequest(); - } - if (phoneBookPresenter != null) { - phoneBookPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt new file mode 100644 index 0000000..e606857 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt @@ -0,0 +1,124 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.net.Uri +import android.text.TextUtils +import com.casic.dcms.R +import com.casic.dcms.adapter.DeptExpandableAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.DeptTreeBean +import com.casic.dcms.bean.PersonBean +import com.casic.dcms.bean.PhoneBookBean +import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl +import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl +import com.casic.dcms.mvp.view.IDeptTreeView +import com.casic.dcms.mvp.view.IPhoneBookView +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.fragment_phone.* +import java.util.* + +class PhonePageFragment : BaseFragment(), IDeptTreeView, IPhoneBookView { + + private lateinit var deptTreePresenter: DeptTreePresenterImpl + private lateinit var phoneBookPresenter: PhoneBookPresenterImpl + private lateinit var expandableAdapter: DeptExpandableAdapter + private val deptList: MutableList = ArrayList() //部门名集合 + private val deptAndPersons: MutableList> = ArrayList() //个人信息集合的集合 + + override fun initLayoutView(): Int { + return R.layout.fragment_phone + } + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deptTreePresenter = DeptTreePresenterImpl(this) + deptTreePresenter.onReadyRetrofitRequest("0") + phoneBookPresenter = PhoneBookPresenterImpl(this) + expandableAdapter = DeptExpandableAdapter(context) + } + + override fun initEvent() {} + + override fun obtainDeptTreeResult(resultBean: DeptTreeBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + //先获取部门树,在往树结构里面加人 + if (resultBean.isSuccess) { + val listBeans = resultBean.data.list + deptList.clear() + for (bean in listBeans) { + deptList.add(bean.name) + } + if (deptList.size > 0) { + phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().deptId) + } + } + } + + override fun obtainPhoneBookResult(resultBean: PhoneBookBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val dataBeans = resultBean.data + deptAndPersons.clear() + for (title in deptList) { + val beanList: MutableList = ArrayList() + for (dataBean in dataBeans) { + if (title == dataBean.deptName) { + val personBean = PersonBean() + personBean.personDept = dataBean.deptName + personBean.personName = dataBean.name + personBean.personPhone = dataBean.phone + beanList.add(personBean) + } + } + deptAndPersons.add(beanList) + } + //展示部门树以及人员 + expandableAdapter.setData(deptList, deptAndPersons) + deptTreeView.setAdapter(expandableAdapter) + //默认展开数据 + for (i in 0 until expandableAdapter.groupCount) { + deptTreeView.expandGroup(i) + } + deptTreeView.setOnChildClickListener { parent, v, groupPosition, childPosition, id -> + val personBean = deptAndPersons[groupPosition][childPosition] + callPhone(personBean.personName, personBean.personPhone) + true + } + } + } + + /** + * 直接呼叫电话 + */ + private fun callPhone(personName: String, personPhone: String) { + if (TextUtils.isEmpty(personPhone)) { + ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR) + return + } + MessageDialogBuilder(context) + .setTitle("提示") + .setMessage("是否确定拨打[$personName]的电话?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + val intent = Intent() + intent.action = Intent.ACTION_CALL + intent.data = Uri.parse("tel:$personPhone") + startActivity(intent) + } + .create().show() + } + + override fun onDestroyView() { + super.onDestroyView() + deptTreePresenter.disposeRetrofitRequest() + phoneBookPresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt new file mode 100644 index 0000000..a33bb4e --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt @@ -0,0 +1,183 @@ +package com.casic.dcms.ui.fragment + +import android.app.ProgressDialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.casic.dcms.BuildConfig +import com.casic.dcms.R +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.bean.NewVersionBean +import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl +import com.casic.dcms.mvp.presenter.UpdatePresenterImpl +import com.casic.dcms.mvp.view.ILoginOutView +import com.casic.dcms.mvp.view.IUpdateVersionView +import com.casic.dcms.ui.ChangePasswordActivity +import com.casic.dcms.ui.HelpfulActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.ui.UserInfoActivity +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IDownloadListener +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MinePageFragment : BaseFragment(), IUpdateVersionView, ILoginOutView { + + private var clipboardManager: ClipboardManager? = null + private lateinit var loginOutPresenter: LoginOutPresenterImpl + private lateinit var updatePresenter: UpdatePresenterImpl + private lateinit var progressDialog: ProgressDialog + + override fun initLayoutView(): Int = R.layout.fragment_mine + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deviceIdView!!.text = OtherUtils.obtainSimCardSerialNumber(context) + versionCodeView!!.text = BuildConfig.VERSION_NAME + loginOutPresenter = LoginOutPresenterImpl(this) + val isAutoLogin = SaveKeyValues.getValue("autoLogin", false) as Boolean + autoLoginSwitch!!.isChecked = isAutoLogin + updatePresenter = UpdatePresenterImpl(this) + clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + + //下载进度条 + progressDialog = ProgressDialog(context) + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + progressDialog.setProgressDrawable(context?.resources!!.getDrawable(R.drawable.bg_progress)) + progressDialog.setCanceledOnTouchOutside(false) + } + + override fun initEvent() { + userNameLayout.setOnClickListener { + startActivity(Intent(context, UserInfoActivity::class.java)) + } + passwordLayout.setOnClickListener { + startActivity(Intent(context, ChangePasswordActivity::class.java)) + } + helpfulLayout.setOnClickListener { + startActivity(Intent(context, HelpfulActivity::class.java)) + } + autoLoginSwitch!!.setOnCheckedChangeListener { buttonView, isChecked -> + SaveKeyValues.putValue("autoLogin", isChecked) + } + copyView.setOnClickListener { + val clipData = ClipData.newPlainText("deviceId", deviceIdView!!.text.toString()) + clipboardManager!!.setPrimaryClip(clipData) + ToastHelper.showToast("复制成功", ToastHelper.SUCCESS) + } + updateVersionView.setOnClickListener { updatePresenter.onReadyRetrofitRequest() } + + loginOutButton!!.setChangeAlphaWhenPress(true) + loginOutButton.setOnClickListener { + MessageDialogBuilder(context) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + loginOutPresenter.onReadyRetrofitRequest() + }.create().show() + } + } + + override fun obtainLoginOutResult(resultBean: ActionResultBean) { + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + } + + override fun showProgress() { + OtherUtils.showLoadingDialog(context, "请求中,请稍后") + } + + override fun hideProgress() { + OtherUtils.dismissLoadingDialog() + } + + override fun obtainVersionResult(resultBean: NewVersionBean) { +// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val data = resultBean.data + val version = data.version + if (BuildConfig.VERSION_NAME == version) { + ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO) + } else { + val downloadUrl = StringHelper.appendDownloadUrl(data.downloadUrl) + //http://111.198.10.15:11409/static/app/v1.1.0.0.apk + MessageDialogBuilder(context) + .setTitle("版本更新") + .setMessage("确定下载新版本吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定", QMUIDialogAction.ActionListener { dialog, index -> + dialog.dismiss() + //下载新版本 + progressDialog.setMessage("下载新版本中...") + progressDialog.show() + if (progressDialog.progress != 0) { + progressDialog.progress = 0 //防止下载到中途却卡住无法再进行下载 + return@ActionListener + } + downloadApk(downloadUrl) + }).create().show() + } + } + } + + //下载apk + private fun downloadApk(url: String) { + FileUtils.downloadFile(url, object : IDownloadListener { + override fun onDownloadStart(totalBytes: Long) { + progressDialog.max = totalBytes.toInt() + } + + override fun onProgressChanged(currentBytes: Long) { + progressDialog.progress = currentBytes.toInt() + } + + override fun onDownloadEnd(file: File) { + progressDialog.progress = 0 //防止下载完成却卡住的情况 + progressDialog.dismiss() + installApk(file) + } + }) + } + + //安装apk文件 + private fun installApk(apk: File) { + val intent = Intent(Intent.ACTION_VIEW) + val data: Uri + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //判断版本大于等于7.0 + // 通过FileProvider创建一个content类型的Uri + data = FileProvider.getUriForFile( + requireContext(), + "com.casic.dcms.install.fileProvider", apk + ) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 给目标应用一个临时授权 + } else { + data = Uri.fromFile(apk) + } + intent.setDataAndType(data, "application/vnd.android.package-archive") + requireContext().startActivity(intent) + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } + + override fun onDestroyView() { + super.onDestroyView() + loginOutPresenter.disposeRetrofitRequest() + updatePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java deleted file mode 100644 index e2488fc..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -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.greendao.NoticeBeanDao; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.igexin.sdk.message.GTTransmitMessage; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; - -import org.jetbrains.annotations.NotNull; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class NoticePageFragment extends BaseFragment { - - private static final String TAG = "NoticePageFragment"; - @BindView(R.id.swipeRecyclerView) - RecyclerView swipeRecyclerView; - - private Context context; - private List noticeBeans = new ArrayList<>(); - private SwipeViewAdapter swipeViewAdapter; - private DaoSession daoSession; - private static WeakReferenceHandler weakReferenceHandler; - - @Override - protected int initLayoutView() { - return R.layout.fragment_notice; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - daoSession = BaseApplication.getDaoSession(); - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeans = daoSession.queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeBeanDao.Properties.PushDate)//按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - - weakReferenceHandler = new WeakReferenceHandler(this); - } - - @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - int position = viewHolder.getAdapterPosition(); - daoSession.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - 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); - } - }); - swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - daoSession.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - - @Override - public void handleMessage(@NotNull Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == Constant.PUSH_MESSAGE_DATA) { - NoticeBean noticeBean = (NoticeBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean);//新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt new file mode 100644 index 0000000..05e6ddb --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt @@ -0,0 +1,152 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.os.Handler +import android.os.Message +import android.text.TextUtils +import android.util.Log +import android.view.ViewGroup +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +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.NoticeBeanDao +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction +import com.qmuiteam.qmui.recyclerView.QMUISwipeAction +import kotlinx.android.synthetic.main.fragment_notice.* +import java.lang.ref.WeakReference +import java.util.* + +class NoticePageFragment : BaseFragment() { + + private lateinit var noticeBeanDao: NoticeBeanDao + private lateinit var swipeViewAdapter: SwipeViewAdapter + private var noticeBeans: MutableList = ArrayList() + + override fun initLayoutView(): Int = R.layout.fragment_notice + + override fun setupTopBarLayout() { + + } + + override fun initData() { + swipeViewAdapter = SwipeViewAdapter(context) + //根据loginName加载历史数据 + val account = StringHelper.getUserAccount() + if (TextUtils.isEmpty(account)) { + return + } + noticeBeanDao = BaseApplication.getDaoSession().noticeBeanDao + noticeBeans = noticeBeanDao.queryBuilder() + .where(NoticeBeanDao.Properties.UserAccount.eq(account)) + .orderDesc(NoticeBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 + .list() + swipeViewAdapter.setData(noticeBeans) + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initEvent() { + val swipeAction = QMUIRVItemSwipeAction(true, object : QMUIRVItemSwipeAction.Callback() { + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = viewHolder.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + + override fun getSwipeDirection( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ): Int { + return QMUIRVItemSwipeAction.SWIPE_LEFT + } + + override fun onClickAction( + swipeAction: QMUIRVItemSwipeAction, + selected: RecyclerView.ViewHolder, + action: QMUISwipeAction + ) { + super.onClickAction(swipeAction, selected, action) + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = selected.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + }) + swipeAction.attachToRecyclerView(swipeRecyclerView) + swipeRecyclerView!!.layoutManager = object : LinearLayoutManager(context) { + override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams { + return RecyclerView.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + } + swipeRecyclerView!!.addItemDecoration( + DividerItemDecoration( + context, + DividerItemDecoration.VERTICAL + ) + ) + swipeRecyclerView!!.adapter = swipeViewAdapter + swipeViewAdapter.setOnItemClickListener { position -> //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + + //点击之后之后,未读消息变为已读消息 + val noticeBean = noticeBeans[position] + noticeBean.isRead = "0" + noticeBeanDao.update(noticeBean) + swipeViewAdapter.notifyDataSetChanged() + val caseId = noticeBeans[position].caseId + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + } + + private class WeakReferenceHandler(fragment: NoticePageFragment) : Handler() { + private val reference: WeakReference = WeakReference(fragment) + override fun handleMessage(msg: Message) { + val noticePageFragment: NoticePageFragment? + try { + noticePageFragment = reference.get() + val noticeBeans = noticePageFragment!!.noticeBeans + if (msg.what == Constant.PUSH_MESSAGE_DATA) { + val noticeBean = msg.obj as NoticeBean + Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.caseId) + noticeBeans.add(0, noticeBean) //新消息永远放到第一个 + //更新数据 + noticePageFragment.swipeViewAdapter.setData(noticeBeans) + } + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + + } + + companion object { + private const val TAG = "NoticePageFragment" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java deleted file mode 100644 index 13aa09b..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.text.TextUtils; -import android.view.View; -import android.widget.ExpandableListView; - -import com.casic.dcms.R; -import com.casic.dcms.adapter.DeptExpandableAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.DeptTreeBean; -import com.casic.dcms.bean.PersonBean; -import com.casic.dcms.bean.PhoneBookBean; -import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl; -import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl; -import com.casic.dcms.mvp.view.IDeptTreeView; -import com.casic.dcms.mvp.view.IPhoneBookView; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; - -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class PhonePageFragment extends BaseFragment implements IDeptTreeView, IPhoneBookView { - - private static final String TAG = "PhonePageFragment"; - - @BindView(R.id.deptTreeView) - ExpandableListView deptTreeView; - - private Context context; - private DeptTreePresenterImpl deptTreePresenter; - private PhoneBookPresenterImpl phoneBookPresenter; - private List deptList = new ArrayList<>();//部门名集合 - private List> deptAndPersons = new ArrayList<>();//个人信息集合的集合 - private DeptExpandableAdapter expandableAdapter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_phone; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deptTreePresenter = new DeptTreePresenterImpl(this); - deptTreePresenter.onReadyRetrofitRequest("0"); - phoneBookPresenter = new PhoneBookPresenterImpl(this); - expandableAdapter = new DeptExpandableAdapter(context); - } - - @Override - protected void initEvent() { - - } - - - @Override - public void obtainDeptTreeResult(DeptTreeBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - //先获取部门树,在往树结构里面加人 - if (resultBean.isSuccess()) { - List listBeans = resultBean.getData().getList(); - deptList.clear(); - for (DeptTreeBean.DataBean.ListBean bean : listBeans) { - deptList.add(bean.getName()); - } - if (deptList.size() > 0) { - phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().getDeptId()); - } - } - } - - @Override - public void obtainPhoneBookResult(PhoneBookBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - List dataBeans = resultBean.getData(); - deptAndPersons.clear(); - for (String title : deptList) { - List beanList = new ArrayList<>(); - for (PhoneBookBean.DataBean dataBean : dataBeans) { - if (title.equals(dataBean.getDeptName())) { - PersonBean personBean = new PersonBean(); - personBean.setPersonDept(dataBean.getDeptName()); - personBean.setPersonName(dataBean.getName()); - personBean.setPersonPhone(dataBean.getPhone()); - - beanList.add(personBean); - } - } - deptAndPersons.add(beanList); - } - //展示部门树以及人员 - expandableAdapter.setData(deptList, deptAndPersons); - deptTreeView.setAdapter(expandableAdapter); - //默认展开数据 - for (int i = 0; i < expandableAdapter.getGroupCount(); i++) { - deptTreeView.expandGroup(i); - } - deptTreeView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { - @Override - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - PersonBean personBean = deptAndPersons.get(groupPosition).get(childPosition); - callPhone(personBean.getPersonName(), personBean.getPersonPhone()); - return true; - } - }); - } - } - - /** - * 直接呼叫电话 - */ - private void callPhone(String personName, String personPhone) { - if (TextUtils.isEmpty(personPhone)) { - ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR); - return; - } - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("提示") - .setMessage("是否确定拨打[" + personName + "]的电话?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_CALL); - intent.setData(Uri.parse("tel:" + personPhone)); - startActivity(intent); - } - }) - .create().show(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (deptTreePresenter != null) { - deptTreePresenter.disposeRetrofitRequest(); - } - if (phoneBookPresenter != null) { - phoneBookPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt new file mode 100644 index 0000000..e606857 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt @@ -0,0 +1,124 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.net.Uri +import android.text.TextUtils +import com.casic.dcms.R +import com.casic.dcms.adapter.DeptExpandableAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.DeptTreeBean +import com.casic.dcms.bean.PersonBean +import com.casic.dcms.bean.PhoneBookBean +import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl +import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl +import com.casic.dcms.mvp.view.IDeptTreeView +import com.casic.dcms.mvp.view.IPhoneBookView +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.fragment_phone.* +import java.util.* + +class PhonePageFragment : BaseFragment(), IDeptTreeView, IPhoneBookView { + + private lateinit var deptTreePresenter: DeptTreePresenterImpl + private lateinit var phoneBookPresenter: PhoneBookPresenterImpl + private lateinit var expandableAdapter: DeptExpandableAdapter + private val deptList: MutableList = ArrayList() //部门名集合 + private val deptAndPersons: MutableList> = ArrayList() //个人信息集合的集合 + + override fun initLayoutView(): Int { + return R.layout.fragment_phone + } + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deptTreePresenter = DeptTreePresenterImpl(this) + deptTreePresenter.onReadyRetrofitRequest("0") + phoneBookPresenter = PhoneBookPresenterImpl(this) + expandableAdapter = DeptExpandableAdapter(context) + } + + override fun initEvent() {} + + override fun obtainDeptTreeResult(resultBean: DeptTreeBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + //先获取部门树,在往树结构里面加人 + if (resultBean.isSuccess) { + val listBeans = resultBean.data.list + deptList.clear() + for (bean in listBeans) { + deptList.add(bean.name) + } + if (deptList.size > 0) { + phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().deptId) + } + } + } + + override fun obtainPhoneBookResult(resultBean: PhoneBookBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val dataBeans = resultBean.data + deptAndPersons.clear() + for (title in deptList) { + val beanList: MutableList = ArrayList() + for (dataBean in dataBeans) { + if (title == dataBean.deptName) { + val personBean = PersonBean() + personBean.personDept = dataBean.deptName + personBean.personName = dataBean.name + personBean.personPhone = dataBean.phone + beanList.add(personBean) + } + } + deptAndPersons.add(beanList) + } + //展示部门树以及人员 + expandableAdapter.setData(deptList, deptAndPersons) + deptTreeView.setAdapter(expandableAdapter) + //默认展开数据 + for (i in 0 until expandableAdapter.groupCount) { + deptTreeView.expandGroup(i) + } + deptTreeView.setOnChildClickListener { parent, v, groupPosition, childPosition, id -> + val personBean = deptAndPersons[groupPosition][childPosition] + callPhone(personBean.personName, personBean.personPhone) + true + } + } + } + + /** + * 直接呼叫电话 + */ + private fun callPhone(personName: String, personPhone: String) { + if (TextUtils.isEmpty(personPhone)) { + ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR) + return + } + MessageDialogBuilder(context) + .setTitle("提示") + .setMessage("是否确定拨打[$personName]的电话?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + val intent = Intent() + intent.action = Intent.ACTION_CALL + intent.data = Uri.parse("tel:$personPhone") + startActivity(intent) + } + .create().show() + } + + override fun onDestroyView() { + super.onDestroyView() + deptTreePresenter.disposeRetrofitRequest() + phoneBookPresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/Constant.java b/app/src/main/java/com/casic/dcms/utils/Constant.java index 9bc9aa1..e41c903 100644 --- a/app/src/main/java/com/casic/dcms/utils/Constant.java +++ b/app/src/main/java/com/casic/dcms/utils/Constant.java @@ -81,6 +81,31 @@ public static final double DELTA_LNG_75 = 0.00075; public static final double DELTA_LAT_75 = 0.00075; + /** + * 西路社区:116.0497949886485,27.7523090448274 + * 永胜、中山社区:116.04801256908105,27.764489266672403 + * 城北社区:116.05083134025335,27.78274489130171 + * 一木社区:116.06179579161108,27.780238298884917 + * 新街社区:116.0569392645266,27.775902775818285 + * 南道社区:116.05398381594571,27.765387699087427 + * 胜利社区:116.05763011146338,27.758979599138858 + * 黄家社区:116.06998477480374,27.766637205647783 + * 中大社区:116.06510639190675,27.752823008396483 + * 中大、子正社区:116.08546817209574,27.758020310248185 + * 子正、高新区:116.11514568328859,27.774506608946538 + */ + public static final double[] XILU = {116.0497949886485, 27.7523090448274}; + public static final double[] YONG_ZHONG = {116.04801256908105, 27.764489266672403}; + public static final double[] CHENGBEI = {116.05083134025335, 27.78274489130171}; + public static final double[] YIMU = {116.06179579161108, 27.780238298884917}; + public static final double[] XINJIE = {116.0569392645266, 27.775902775818285}; + public static final double[] NANDAO = {116.05398381594571, 27.765387699087427}; + public static final double[] SHENGLI = {116.05763011146338, 27.758979599138858}; + public static final double[] HUANGJIA = {116.06998477480374, 27.766637205647783}; + public static final double[] ZHONGDA = {116.06510639190675, 27.752823008396483}; + public static final double[] ZHONG_ZI = {116.08546817209574, 27.758020310248185}; + public static final double[] ZI_GAO = {116.11514568328859, 27.774506608946538}; + //单独网络请求接口名 public static final String SHOP_DETAIL = "/shop/merchant/detail?merchantId="; public static final String SHOP_PUNISH_LIST = "/shop/punish/listByMerchant?merchantId="; diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt new file mode 100644 index 0000000..a33bb4e --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt @@ -0,0 +1,183 @@ +package com.casic.dcms.ui.fragment + +import android.app.ProgressDialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.casic.dcms.BuildConfig +import com.casic.dcms.R +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.bean.NewVersionBean +import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl +import com.casic.dcms.mvp.presenter.UpdatePresenterImpl +import com.casic.dcms.mvp.view.ILoginOutView +import com.casic.dcms.mvp.view.IUpdateVersionView +import com.casic.dcms.ui.ChangePasswordActivity +import com.casic.dcms.ui.HelpfulActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.ui.UserInfoActivity +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IDownloadListener +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MinePageFragment : BaseFragment(), IUpdateVersionView, ILoginOutView { + + private var clipboardManager: ClipboardManager? = null + private lateinit var loginOutPresenter: LoginOutPresenterImpl + private lateinit var updatePresenter: UpdatePresenterImpl + private lateinit var progressDialog: ProgressDialog + + override fun initLayoutView(): Int = R.layout.fragment_mine + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deviceIdView!!.text = OtherUtils.obtainSimCardSerialNumber(context) + versionCodeView!!.text = BuildConfig.VERSION_NAME + loginOutPresenter = LoginOutPresenterImpl(this) + val isAutoLogin = SaveKeyValues.getValue("autoLogin", false) as Boolean + autoLoginSwitch!!.isChecked = isAutoLogin + updatePresenter = UpdatePresenterImpl(this) + clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + + //下载进度条 + progressDialog = ProgressDialog(context) + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + progressDialog.setProgressDrawable(context?.resources!!.getDrawable(R.drawable.bg_progress)) + progressDialog.setCanceledOnTouchOutside(false) + } + + override fun initEvent() { + userNameLayout.setOnClickListener { + startActivity(Intent(context, UserInfoActivity::class.java)) + } + passwordLayout.setOnClickListener { + startActivity(Intent(context, ChangePasswordActivity::class.java)) + } + helpfulLayout.setOnClickListener { + startActivity(Intent(context, HelpfulActivity::class.java)) + } + autoLoginSwitch!!.setOnCheckedChangeListener { buttonView, isChecked -> + SaveKeyValues.putValue("autoLogin", isChecked) + } + copyView.setOnClickListener { + val clipData = ClipData.newPlainText("deviceId", deviceIdView!!.text.toString()) + clipboardManager!!.setPrimaryClip(clipData) + ToastHelper.showToast("复制成功", ToastHelper.SUCCESS) + } + updateVersionView.setOnClickListener { updatePresenter.onReadyRetrofitRequest() } + + loginOutButton!!.setChangeAlphaWhenPress(true) + loginOutButton.setOnClickListener { + MessageDialogBuilder(context) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + loginOutPresenter.onReadyRetrofitRequest() + }.create().show() + } + } + + override fun obtainLoginOutResult(resultBean: ActionResultBean) { + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + } + + override fun showProgress() { + OtherUtils.showLoadingDialog(context, "请求中,请稍后") + } + + override fun hideProgress() { + OtherUtils.dismissLoadingDialog() + } + + override fun obtainVersionResult(resultBean: NewVersionBean) { +// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val data = resultBean.data + val version = data.version + if (BuildConfig.VERSION_NAME == version) { + ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO) + } else { + val downloadUrl = StringHelper.appendDownloadUrl(data.downloadUrl) + //http://111.198.10.15:11409/static/app/v1.1.0.0.apk + MessageDialogBuilder(context) + .setTitle("版本更新") + .setMessage("确定下载新版本吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定", QMUIDialogAction.ActionListener { dialog, index -> + dialog.dismiss() + //下载新版本 + progressDialog.setMessage("下载新版本中...") + progressDialog.show() + if (progressDialog.progress != 0) { + progressDialog.progress = 0 //防止下载到中途却卡住无法再进行下载 + return@ActionListener + } + downloadApk(downloadUrl) + }).create().show() + } + } + } + + //下载apk + private fun downloadApk(url: String) { + FileUtils.downloadFile(url, object : IDownloadListener { + override fun onDownloadStart(totalBytes: Long) { + progressDialog.max = totalBytes.toInt() + } + + override fun onProgressChanged(currentBytes: Long) { + progressDialog.progress = currentBytes.toInt() + } + + override fun onDownloadEnd(file: File) { + progressDialog.progress = 0 //防止下载完成却卡住的情况 + progressDialog.dismiss() + installApk(file) + } + }) + } + + //安装apk文件 + private fun installApk(apk: File) { + val intent = Intent(Intent.ACTION_VIEW) + val data: Uri + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //判断版本大于等于7.0 + // 通过FileProvider创建一个content类型的Uri + data = FileProvider.getUriForFile( + requireContext(), + "com.casic.dcms.install.fileProvider", apk + ) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 给目标应用一个临时授权 + } else { + data = Uri.fromFile(apk) + } + intent.setDataAndType(data, "application/vnd.android.package-archive") + requireContext().startActivity(intent) + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } + + override fun onDestroyView() { + super.onDestroyView() + loginOutPresenter.disposeRetrofitRequest() + updatePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java deleted file mode 100644 index e2488fc..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -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.greendao.NoticeBeanDao; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.igexin.sdk.message.GTTransmitMessage; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; - -import org.jetbrains.annotations.NotNull; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class NoticePageFragment extends BaseFragment { - - private static final String TAG = "NoticePageFragment"; - @BindView(R.id.swipeRecyclerView) - RecyclerView swipeRecyclerView; - - private Context context; - private List noticeBeans = new ArrayList<>(); - private SwipeViewAdapter swipeViewAdapter; - private DaoSession daoSession; - private static WeakReferenceHandler weakReferenceHandler; - - @Override - protected int initLayoutView() { - return R.layout.fragment_notice; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - daoSession = BaseApplication.getDaoSession(); - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeans = daoSession.queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeBeanDao.Properties.PushDate)//按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - - weakReferenceHandler = new WeakReferenceHandler(this); - } - - @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - int position = viewHolder.getAdapterPosition(); - daoSession.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - 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); - } - }); - swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - daoSession.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - - @Override - public void handleMessage(@NotNull Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == Constant.PUSH_MESSAGE_DATA) { - NoticeBean noticeBean = (NoticeBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean);//新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt new file mode 100644 index 0000000..05e6ddb --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt @@ -0,0 +1,152 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.os.Handler +import android.os.Message +import android.text.TextUtils +import android.util.Log +import android.view.ViewGroup +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +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.NoticeBeanDao +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction +import com.qmuiteam.qmui.recyclerView.QMUISwipeAction +import kotlinx.android.synthetic.main.fragment_notice.* +import java.lang.ref.WeakReference +import java.util.* + +class NoticePageFragment : BaseFragment() { + + private lateinit var noticeBeanDao: NoticeBeanDao + private lateinit var swipeViewAdapter: SwipeViewAdapter + private var noticeBeans: MutableList = ArrayList() + + override fun initLayoutView(): Int = R.layout.fragment_notice + + override fun setupTopBarLayout() { + + } + + override fun initData() { + swipeViewAdapter = SwipeViewAdapter(context) + //根据loginName加载历史数据 + val account = StringHelper.getUserAccount() + if (TextUtils.isEmpty(account)) { + return + } + noticeBeanDao = BaseApplication.getDaoSession().noticeBeanDao + noticeBeans = noticeBeanDao.queryBuilder() + .where(NoticeBeanDao.Properties.UserAccount.eq(account)) + .orderDesc(NoticeBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 + .list() + swipeViewAdapter.setData(noticeBeans) + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initEvent() { + val swipeAction = QMUIRVItemSwipeAction(true, object : QMUIRVItemSwipeAction.Callback() { + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = viewHolder.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + + override fun getSwipeDirection( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ): Int { + return QMUIRVItemSwipeAction.SWIPE_LEFT + } + + override fun onClickAction( + swipeAction: QMUIRVItemSwipeAction, + selected: RecyclerView.ViewHolder, + action: QMUISwipeAction + ) { + super.onClickAction(swipeAction, selected, action) + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = selected.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + }) + swipeAction.attachToRecyclerView(swipeRecyclerView) + swipeRecyclerView!!.layoutManager = object : LinearLayoutManager(context) { + override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams { + return RecyclerView.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + } + swipeRecyclerView!!.addItemDecoration( + DividerItemDecoration( + context, + DividerItemDecoration.VERTICAL + ) + ) + swipeRecyclerView!!.adapter = swipeViewAdapter + swipeViewAdapter.setOnItemClickListener { position -> //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + + //点击之后之后,未读消息变为已读消息 + val noticeBean = noticeBeans[position] + noticeBean.isRead = "0" + noticeBeanDao.update(noticeBean) + swipeViewAdapter.notifyDataSetChanged() + val caseId = noticeBeans[position].caseId + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + } + + private class WeakReferenceHandler(fragment: NoticePageFragment) : Handler() { + private val reference: WeakReference = WeakReference(fragment) + override fun handleMessage(msg: Message) { + val noticePageFragment: NoticePageFragment? + try { + noticePageFragment = reference.get() + val noticeBeans = noticePageFragment!!.noticeBeans + if (msg.what == Constant.PUSH_MESSAGE_DATA) { + val noticeBean = msg.obj as NoticeBean + Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.caseId) + noticeBeans.add(0, noticeBean) //新消息永远放到第一个 + //更新数据 + noticePageFragment.swipeViewAdapter.setData(noticeBeans) + } + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + + } + + companion object { + private const val TAG = "NoticePageFragment" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java deleted file mode 100644 index 13aa09b..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.text.TextUtils; -import android.view.View; -import android.widget.ExpandableListView; - -import com.casic.dcms.R; -import com.casic.dcms.adapter.DeptExpandableAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.DeptTreeBean; -import com.casic.dcms.bean.PersonBean; -import com.casic.dcms.bean.PhoneBookBean; -import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl; -import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl; -import com.casic.dcms.mvp.view.IDeptTreeView; -import com.casic.dcms.mvp.view.IPhoneBookView; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; - -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class PhonePageFragment extends BaseFragment implements IDeptTreeView, IPhoneBookView { - - private static final String TAG = "PhonePageFragment"; - - @BindView(R.id.deptTreeView) - ExpandableListView deptTreeView; - - private Context context; - private DeptTreePresenterImpl deptTreePresenter; - private PhoneBookPresenterImpl phoneBookPresenter; - private List deptList = new ArrayList<>();//部门名集合 - private List> deptAndPersons = new ArrayList<>();//个人信息集合的集合 - private DeptExpandableAdapter expandableAdapter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_phone; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deptTreePresenter = new DeptTreePresenterImpl(this); - deptTreePresenter.onReadyRetrofitRequest("0"); - phoneBookPresenter = new PhoneBookPresenterImpl(this); - expandableAdapter = new DeptExpandableAdapter(context); - } - - @Override - protected void initEvent() { - - } - - - @Override - public void obtainDeptTreeResult(DeptTreeBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - //先获取部门树,在往树结构里面加人 - if (resultBean.isSuccess()) { - List listBeans = resultBean.getData().getList(); - deptList.clear(); - for (DeptTreeBean.DataBean.ListBean bean : listBeans) { - deptList.add(bean.getName()); - } - if (deptList.size() > 0) { - phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().getDeptId()); - } - } - } - - @Override - public void obtainPhoneBookResult(PhoneBookBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - List dataBeans = resultBean.getData(); - deptAndPersons.clear(); - for (String title : deptList) { - List beanList = new ArrayList<>(); - for (PhoneBookBean.DataBean dataBean : dataBeans) { - if (title.equals(dataBean.getDeptName())) { - PersonBean personBean = new PersonBean(); - personBean.setPersonDept(dataBean.getDeptName()); - personBean.setPersonName(dataBean.getName()); - personBean.setPersonPhone(dataBean.getPhone()); - - beanList.add(personBean); - } - } - deptAndPersons.add(beanList); - } - //展示部门树以及人员 - expandableAdapter.setData(deptList, deptAndPersons); - deptTreeView.setAdapter(expandableAdapter); - //默认展开数据 - for (int i = 0; i < expandableAdapter.getGroupCount(); i++) { - deptTreeView.expandGroup(i); - } - deptTreeView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { - @Override - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - PersonBean personBean = deptAndPersons.get(groupPosition).get(childPosition); - callPhone(personBean.getPersonName(), personBean.getPersonPhone()); - return true; - } - }); - } - } - - /** - * 直接呼叫电话 - */ - private void callPhone(String personName, String personPhone) { - if (TextUtils.isEmpty(personPhone)) { - ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR); - return; - } - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("提示") - .setMessage("是否确定拨打[" + personName + "]的电话?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_CALL); - intent.setData(Uri.parse("tel:" + personPhone)); - startActivity(intent); - } - }) - .create().show(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (deptTreePresenter != null) { - deptTreePresenter.disposeRetrofitRequest(); - } - if (phoneBookPresenter != null) { - phoneBookPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt new file mode 100644 index 0000000..e606857 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt @@ -0,0 +1,124 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.net.Uri +import android.text.TextUtils +import com.casic.dcms.R +import com.casic.dcms.adapter.DeptExpandableAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.DeptTreeBean +import com.casic.dcms.bean.PersonBean +import com.casic.dcms.bean.PhoneBookBean +import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl +import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl +import com.casic.dcms.mvp.view.IDeptTreeView +import com.casic.dcms.mvp.view.IPhoneBookView +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.fragment_phone.* +import java.util.* + +class PhonePageFragment : BaseFragment(), IDeptTreeView, IPhoneBookView { + + private lateinit var deptTreePresenter: DeptTreePresenterImpl + private lateinit var phoneBookPresenter: PhoneBookPresenterImpl + private lateinit var expandableAdapter: DeptExpandableAdapter + private val deptList: MutableList = ArrayList() //部门名集合 + private val deptAndPersons: MutableList> = ArrayList() //个人信息集合的集合 + + override fun initLayoutView(): Int { + return R.layout.fragment_phone + } + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deptTreePresenter = DeptTreePresenterImpl(this) + deptTreePresenter.onReadyRetrofitRequest("0") + phoneBookPresenter = PhoneBookPresenterImpl(this) + expandableAdapter = DeptExpandableAdapter(context) + } + + override fun initEvent() {} + + override fun obtainDeptTreeResult(resultBean: DeptTreeBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + //先获取部门树,在往树结构里面加人 + if (resultBean.isSuccess) { + val listBeans = resultBean.data.list + deptList.clear() + for (bean in listBeans) { + deptList.add(bean.name) + } + if (deptList.size > 0) { + phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().deptId) + } + } + } + + override fun obtainPhoneBookResult(resultBean: PhoneBookBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val dataBeans = resultBean.data + deptAndPersons.clear() + for (title in deptList) { + val beanList: MutableList = ArrayList() + for (dataBean in dataBeans) { + if (title == dataBean.deptName) { + val personBean = PersonBean() + personBean.personDept = dataBean.deptName + personBean.personName = dataBean.name + personBean.personPhone = dataBean.phone + beanList.add(personBean) + } + } + deptAndPersons.add(beanList) + } + //展示部门树以及人员 + expandableAdapter.setData(deptList, deptAndPersons) + deptTreeView.setAdapter(expandableAdapter) + //默认展开数据 + for (i in 0 until expandableAdapter.groupCount) { + deptTreeView.expandGroup(i) + } + deptTreeView.setOnChildClickListener { parent, v, groupPosition, childPosition, id -> + val personBean = deptAndPersons[groupPosition][childPosition] + callPhone(personBean.personName, personBean.personPhone) + true + } + } + } + + /** + * 直接呼叫电话 + */ + private fun callPhone(personName: String, personPhone: String) { + if (TextUtils.isEmpty(personPhone)) { + ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR) + return + } + MessageDialogBuilder(context) + .setTitle("提示") + .setMessage("是否确定拨打[$personName]的电话?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + val intent = Intent() + intent.action = Intent.ACTION_CALL + intent.data = Uri.parse("tel:$personPhone") + startActivity(intent) + } + .create().show() + } + + override fun onDestroyView() { + super.onDestroyView() + deptTreePresenter.disposeRetrofitRequest() + phoneBookPresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/Constant.java b/app/src/main/java/com/casic/dcms/utils/Constant.java index 9bc9aa1..e41c903 100644 --- a/app/src/main/java/com/casic/dcms/utils/Constant.java +++ b/app/src/main/java/com/casic/dcms/utils/Constant.java @@ -81,6 +81,31 @@ public static final double DELTA_LNG_75 = 0.00075; public static final double DELTA_LAT_75 = 0.00075; + /** + * 西路社区:116.0497949886485,27.7523090448274 + * 永胜、中山社区:116.04801256908105,27.764489266672403 + * 城北社区:116.05083134025335,27.78274489130171 + * 一木社区:116.06179579161108,27.780238298884917 + * 新街社区:116.0569392645266,27.775902775818285 + * 南道社区:116.05398381594571,27.765387699087427 + * 胜利社区:116.05763011146338,27.758979599138858 + * 黄家社区:116.06998477480374,27.766637205647783 + * 中大社区:116.06510639190675,27.752823008396483 + * 中大、子正社区:116.08546817209574,27.758020310248185 + * 子正、高新区:116.11514568328859,27.774506608946538 + */ + public static final double[] XILU = {116.0497949886485, 27.7523090448274}; + public static final double[] YONG_ZHONG = {116.04801256908105, 27.764489266672403}; + public static final double[] CHENGBEI = {116.05083134025335, 27.78274489130171}; + public static final double[] YIMU = {116.06179579161108, 27.780238298884917}; + public static final double[] XINJIE = {116.0569392645266, 27.775902775818285}; + public static final double[] NANDAO = {116.05398381594571, 27.765387699087427}; + public static final double[] SHENGLI = {116.05763011146338, 27.758979599138858}; + public static final double[] HUANGJIA = {116.06998477480374, 27.766637205647783}; + public static final double[] ZHONGDA = {116.06510639190675, 27.752823008396483}; + public static final double[] ZHONG_ZI = {116.08546817209574, 27.758020310248185}; + public static final double[] ZI_GAO = {116.11514568328859, 27.774506608946538}; + //单独网络请求接口名 public static final String SHOP_DETAIL = "/shop/merchant/detail?merchantId="; public static final String SHOP_PUNISH_LIST = "/shop/punish/listByMerchant?merchantId="; diff --git a/app/src/main/java/com/casic/dcms/utils/StringHelper.java b/app/src/main/java/com/casic/dcms/utils/StringHelper.java index a7cb679..df96c00 100644 --- a/app/src/main/java/com/casic/dcms/utils/StringHelper.java +++ b/app/src/main/java/com/casic/dcms/utils/StringHelper.java @@ -1,5 +1,6 @@ package com.casic.dcms.utils; +import android.content.res.AssetManager; import android.text.TextUtils; import android.util.Log; @@ -11,6 +12,9 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -206,6 +210,30 @@ } /** + * 获取本地Asserts文件内容 + */ + public static String getAssetsData(AssetManager manager, String fileName) { + try { + InputStreamReader inputStreamReader = new InputStreamReader(manager.open(fileName)); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + StringBuilder data = new StringBuilder(); + String s; + try { + while ((s = bufferedReader.readLine()) != null) { + data.append(s); + } + Log.d(TAG, "getAssetsData: " + data); + return data.toString(); + } catch (IOException e) { + e.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** * 三包处罚转换 */ public static String StringToType(String s) { diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 681f41a..3cc336b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt new file mode 100644 index 0000000..a33bb4e --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt @@ -0,0 +1,183 @@ +package com.casic.dcms.ui.fragment + +import android.app.ProgressDialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.casic.dcms.BuildConfig +import com.casic.dcms.R +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.bean.NewVersionBean +import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl +import com.casic.dcms.mvp.presenter.UpdatePresenterImpl +import com.casic.dcms.mvp.view.ILoginOutView +import com.casic.dcms.mvp.view.IUpdateVersionView +import com.casic.dcms.ui.ChangePasswordActivity +import com.casic.dcms.ui.HelpfulActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.ui.UserInfoActivity +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IDownloadListener +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MinePageFragment : BaseFragment(), IUpdateVersionView, ILoginOutView { + + private var clipboardManager: ClipboardManager? = null + private lateinit var loginOutPresenter: LoginOutPresenterImpl + private lateinit var updatePresenter: UpdatePresenterImpl + private lateinit var progressDialog: ProgressDialog + + override fun initLayoutView(): Int = R.layout.fragment_mine + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deviceIdView!!.text = OtherUtils.obtainSimCardSerialNumber(context) + versionCodeView!!.text = BuildConfig.VERSION_NAME + loginOutPresenter = LoginOutPresenterImpl(this) + val isAutoLogin = SaveKeyValues.getValue("autoLogin", false) as Boolean + autoLoginSwitch!!.isChecked = isAutoLogin + updatePresenter = UpdatePresenterImpl(this) + clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + + //下载进度条 + progressDialog = ProgressDialog(context) + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + progressDialog.setProgressDrawable(context?.resources!!.getDrawable(R.drawable.bg_progress)) + progressDialog.setCanceledOnTouchOutside(false) + } + + override fun initEvent() { + userNameLayout.setOnClickListener { + startActivity(Intent(context, UserInfoActivity::class.java)) + } + passwordLayout.setOnClickListener { + startActivity(Intent(context, ChangePasswordActivity::class.java)) + } + helpfulLayout.setOnClickListener { + startActivity(Intent(context, HelpfulActivity::class.java)) + } + autoLoginSwitch!!.setOnCheckedChangeListener { buttonView, isChecked -> + SaveKeyValues.putValue("autoLogin", isChecked) + } + copyView.setOnClickListener { + val clipData = ClipData.newPlainText("deviceId", deviceIdView!!.text.toString()) + clipboardManager!!.setPrimaryClip(clipData) + ToastHelper.showToast("复制成功", ToastHelper.SUCCESS) + } + updateVersionView.setOnClickListener { updatePresenter.onReadyRetrofitRequest() } + + loginOutButton!!.setChangeAlphaWhenPress(true) + loginOutButton.setOnClickListener { + MessageDialogBuilder(context) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + loginOutPresenter.onReadyRetrofitRequest() + }.create().show() + } + } + + override fun obtainLoginOutResult(resultBean: ActionResultBean) { + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + } + + override fun showProgress() { + OtherUtils.showLoadingDialog(context, "请求中,请稍后") + } + + override fun hideProgress() { + OtherUtils.dismissLoadingDialog() + } + + override fun obtainVersionResult(resultBean: NewVersionBean) { +// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val data = resultBean.data + val version = data.version + if (BuildConfig.VERSION_NAME == version) { + ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO) + } else { + val downloadUrl = StringHelper.appendDownloadUrl(data.downloadUrl) + //http://111.198.10.15:11409/static/app/v1.1.0.0.apk + MessageDialogBuilder(context) + .setTitle("版本更新") + .setMessage("确定下载新版本吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定", QMUIDialogAction.ActionListener { dialog, index -> + dialog.dismiss() + //下载新版本 + progressDialog.setMessage("下载新版本中...") + progressDialog.show() + if (progressDialog.progress != 0) { + progressDialog.progress = 0 //防止下载到中途却卡住无法再进行下载 + return@ActionListener + } + downloadApk(downloadUrl) + }).create().show() + } + } + } + + //下载apk + private fun downloadApk(url: String) { + FileUtils.downloadFile(url, object : IDownloadListener { + override fun onDownloadStart(totalBytes: Long) { + progressDialog.max = totalBytes.toInt() + } + + override fun onProgressChanged(currentBytes: Long) { + progressDialog.progress = currentBytes.toInt() + } + + override fun onDownloadEnd(file: File) { + progressDialog.progress = 0 //防止下载完成却卡住的情况 + progressDialog.dismiss() + installApk(file) + } + }) + } + + //安装apk文件 + private fun installApk(apk: File) { + val intent = Intent(Intent.ACTION_VIEW) + val data: Uri + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //判断版本大于等于7.0 + // 通过FileProvider创建一个content类型的Uri + data = FileProvider.getUriForFile( + requireContext(), + "com.casic.dcms.install.fileProvider", apk + ) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 给目标应用一个临时授权 + } else { + data = Uri.fromFile(apk) + } + intent.setDataAndType(data, "application/vnd.android.package-archive") + requireContext().startActivity(intent) + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } + + override fun onDestroyView() { + super.onDestroyView() + loginOutPresenter.disposeRetrofitRequest() + updatePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java deleted file mode 100644 index e2488fc..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -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.greendao.NoticeBeanDao; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.igexin.sdk.message.GTTransmitMessage; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; - -import org.jetbrains.annotations.NotNull; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class NoticePageFragment extends BaseFragment { - - private static final String TAG = "NoticePageFragment"; - @BindView(R.id.swipeRecyclerView) - RecyclerView swipeRecyclerView; - - private Context context; - private List noticeBeans = new ArrayList<>(); - private SwipeViewAdapter swipeViewAdapter; - private DaoSession daoSession; - private static WeakReferenceHandler weakReferenceHandler; - - @Override - protected int initLayoutView() { - return R.layout.fragment_notice; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - daoSession = BaseApplication.getDaoSession(); - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeans = daoSession.queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeBeanDao.Properties.PushDate)//按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - - weakReferenceHandler = new WeakReferenceHandler(this); - } - - @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - int position = viewHolder.getAdapterPosition(); - daoSession.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - 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); - } - }); - swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - daoSession.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - - @Override - public void handleMessage(@NotNull Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == Constant.PUSH_MESSAGE_DATA) { - NoticeBean noticeBean = (NoticeBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean);//新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt new file mode 100644 index 0000000..05e6ddb --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt @@ -0,0 +1,152 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.os.Handler +import android.os.Message +import android.text.TextUtils +import android.util.Log +import android.view.ViewGroup +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +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.NoticeBeanDao +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction +import com.qmuiteam.qmui.recyclerView.QMUISwipeAction +import kotlinx.android.synthetic.main.fragment_notice.* +import java.lang.ref.WeakReference +import java.util.* + +class NoticePageFragment : BaseFragment() { + + private lateinit var noticeBeanDao: NoticeBeanDao + private lateinit var swipeViewAdapter: SwipeViewAdapter + private var noticeBeans: MutableList = ArrayList() + + override fun initLayoutView(): Int = R.layout.fragment_notice + + override fun setupTopBarLayout() { + + } + + override fun initData() { + swipeViewAdapter = SwipeViewAdapter(context) + //根据loginName加载历史数据 + val account = StringHelper.getUserAccount() + if (TextUtils.isEmpty(account)) { + return + } + noticeBeanDao = BaseApplication.getDaoSession().noticeBeanDao + noticeBeans = noticeBeanDao.queryBuilder() + .where(NoticeBeanDao.Properties.UserAccount.eq(account)) + .orderDesc(NoticeBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 + .list() + swipeViewAdapter.setData(noticeBeans) + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initEvent() { + val swipeAction = QMUIRVItemSwipeAction(true, object : QMUIRVItemSwipeAction.Callback() { + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = viewHolder.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + + override fun getSwipeDirection( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ): Int { + return QMUIRVItemSwipeAction.SWIPE_LEFT + } + + override fun onClickAction( + swipeAction: QMUIRVItemSwipeAction, + selected: RecyclerView.ViewHolder, + action: QMUISwipeAction + ) { + super.onClickAction(swipeAction, selected, action) + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = selected.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + }) + swipeAction.attachToRecyclerView(swipeRecyclerView) + swipeRecyclerView!!.layoutManager = object : LinearLayoutManager(context) { + override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams { + return RecyclerView.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + } + swipeRecyclerView!!.addItemDecoration( + DividerItemDecoration( + context, + DividerItemDecoration.VERTICAL + ) + ) + swipeRecyclerView!!.adapter = swipeViewAdapter + swipeViewAdapter.setOnItemClickListener { position -> //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + + //点击之后之后,未读消息变为已读消息 + val noticeBean = noticeBeans[position] + noticeBean.isRead = "0" + noticeBeanDao.update(noticeBean) + swipeViewAdapter.notifyDataSetChanged() + val caseId = noticeBeans[position].caseId + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + } + + private class WeakReferenceHandler(fragment: NoticePageFragment) : Handler() { + private val reference: WeakReference = WeakReference(fragment) + override fun handleMessage(msg: Message) { + val noticePageFragment: NoticePageFragment? + try { + noticePageFragment = reference.get() + val noticeBeans = noticePageFragment!!.noticeBeans + if (msg.what == Constant.PUSH_MESSAGE_DATA) { + val noticeBean = msg.obj as NoticeBean + Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.caseId) + noticeBeans.add(0, noticeBean) //新消息永远放到第一个 + //更新数据 + noticePageFragment.swipeViewAdapter.setData(noticeBeans) + } + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + + } + + companion object { + private const val TAG = "NoticePageFragment" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java deleted file mode 100644 index 13aa09b..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.text.TextUtils; -import android.view.View; -import android.widget.ExpandableListView; - -import com.casic.dcms.R; -import com.casic.dcms.adapter.DeptExpandableAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.DeptTreeBean; -import com.casic.dcms.bean.PersonBean; -import com.casic.dcms.bean.PhoneBookBean; -import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl; -import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl; -import com.casic.dcms.mvp.view.IDeptTreeView; -import com.casic.dcms.mvp.view.IPhoneBookView; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; - -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class PhonePageFragment extends BaseFragment implements IDeptTreeView, IPhoneBookView { - - private static final String TAG = "PhonePageFragment"; - - @BindView(R.id.deptTreeView) - ExpandableListView deptTreeView; - - private Context context; - private DeptTreePresenterImpl deptTreePresenter; - private PhoneBookPresenterImpl phoneBookPresenter; - private List deptList = new ArrayList<>();//部门名集合 - private List> deptAndPersons = new ArrayList<>();//个人信息集合的集合 - private DeptExpandableAdapter expandableAdapter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_phone; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deptTreePresenter = new DeptTreePresenterImpl(this); - deptTreePresenter.onReadyRetrofitRequest("0"); - phoneBookPresenter = new PhoneBookPresenterImpl(this); - expandableAdapter = new DeptExpandableAdapter(context); - } - - @Override - protected void initEvent() { - - } - - - @Override - public void obtainDeptTreeResult(DeptTreeBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - //先获取部门树,在往树结构里面加人 - if (resultBean.isSuccess()) { - List listBeans = resultBean.getData().getList(); - deptList.clear(); - for (DeptTreeBean.DataBean.ListBean bean : listBeans) { - deptList.add(bean.getName()); - } - if (deptList.size() > 0) { - phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().getDeptId()); - } - } - } - - @Override - public void obtainPhoneBookResult(PhoneBookBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - List dataBeans = resultBean.getData(); - deptAndPersons.clear(); - for (String title : deptList) { - List beanList = new ArrayList<>(); - for (PhoneBookBean.DataBean dataBean : dataBeans) { - if (title.equals(dataBean.getDeptName())) { - PersonBean personBean = new PersonBean(); - personBean.setPersonDept(dataBean.getDeptName()); - personBean.setPersonName(dataBean.getName()); - personBean.setPersonPhone(dataBean.getPhone()); - - beanList.add(personBean); - } - } - deptAndPersons.add(beanList); - } - //展示部门树以及人员 - expandableAdapter.setData(deptList, deptAndPersons); - deptTreeView.setAdapter(expandableAdapter); - //默认展开数据 - for (int i = 0; i < expandableAdapter.getGroupCount(); i++) { - deptTreeView.expandGroup(i); - } - deptTreeView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { - @Override - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - PersonBean personBean = deptAndPersons.get(groupPosition).get(childPosition); - callPhone(personBean.getPersonName(), personBean.getPersonPhone()); - return true; - } - }); - } - } - - /** - * 直接呼叫电话 - */ - private void callPhone(String personName, String personPhone) { - if (TextUtils.isEmpty(personPhone)) { - ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR); - return; - } - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("提示") - .setMessage("是否确定拨打[" + personName + "]的电话?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_CALL); - intent.setData(Uri.parse("tel:" + personPhone)); - startActivity(intent); - } - }) - .create().show(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (deptTreePresenter != null) { - deptTreePresenter.disposeRetrofitRequest(); - } - if (phoneBookPresenter != null) { - phoneBookPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt new file mode 100644 index 0000000..e606857 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt @@ -0,0 +1,124 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.net.Uri +import android.text.TextUtils +import com.casic.dcms.R +import com.casic.dcms.adapter.DeptExpandableAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.DeptTreeBean +import com.casic.dcms.bean.PersonBean +import com.casic.dcms.bean.PhoneBookBean +import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl +import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl +import com.casic.dcms.mvp.view.IDeptTreeView +import com.casic.dcms.mvp.view.IPhoneBookView +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.fragment_phone.* +import java.util.* + +class PhonePageFragment : BaseFragment(), IDeptTreeView, IPhoneBookView { + + private lateinit var deptTreePresenter: DeptTreePresenterImpl + private lateinit var phoneBookPresenter: PhoneBookPresenterImpl + private lateinit var expandableAdapter: DeptExpandableAdapter + private val deptList: MutableList = ArrayList() //部门名集合 + private val deptAndPersons: MutableList> = ArrayList() //个人信息集合的集合 + + override fun initLayoutView(): Int { + return R.layout.fragment_phone + } + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deptTreePresenter = DeptTreePresenterImpl(this) + deptTreePresenter.onReadyRetrofitRequest("0") + phoneBookPresenter = PhoneBookPresenterImpl(this) + expandableAdapter = DeptExpandableAdapter(context) + } + + override fun initEvent() {} + + override fun obtainDeptTreeResult(resultBean: DeptTreeBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + //先获取部门树,在往树结构里面加人 + if (resultBean.isSuccess) { + val listBeans = resultBean.data.list + deptList.clear() + for (bean in listBeans) { + deptList.add(bean.name) + } + if (deptList.size > 0) { + phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().deptId) + } + } + } + + override fun obtainPhoneBookResult(resultBean: PhoneBookBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val dataBeans = resultBean.data + deptAndPersons.clear() + for (title in deptList) { + val beanList: MutableList = ArrayList() + for (dataBean in dataBeans) { + if (title == dataBean.deptName) { + val personBean = PersonBean() + personBean.personDept = dataBean.deptName + personBean.personName = dataBean.name + personBean.personPhone = dataBean.phone + beanList.add(personBean) + } + } + deptAndPersons.add(beanList) + } + //展示部门树以及人员 + expandableAdapter.setData(deptList, deptAndPersons) + deptTreeView.setAdapter(expandableAdapter) + //默认展开数据 + for (i in 0 until expandableAdapter.groupCount) { + deptTreeView.expandGroup(i) + } + deptTreeView.setOnChildClickListener { parent, v, groupPosition, childPosition, id -> + val personBean = deptAndPersons[groupPosition][childPosition] + callPhone(personBean.personName, personBean.personPhone) + true + } + } + } + + /** + * 直接呼叫电话 + */ + private fun callPhone(personName: String, personPhone: String) { + if (TextUtils.isEmpty(personPhone)) { + ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR) + return + } + MessageDialogBuilder(context) + .setTitle("提示") + .setMessage("是否确定拨打[$personName]的电话?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + val intent = Intent() + intent.action = Intent.ACTION_CALL + intent.data = Uri.parse("tel:$personPhone") + startActivity(intent) + } + .create().show() + } + + override fun onDestroyView() { + super.onDestroyView() + deptTreePresenter.disposeRetrofitRequest() + phoneBookPresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/Constant.java b/app/src/main/java/com/casic/dcms/utils/Constant.java index 9bc9aa1..e41c903 100644 --- a/app/src/main/java/com/casic/dcms/utils/Constant.java +++ b/app/src/main/java/com/casic/dcms/utils/Constant.java @@ -81,6 +81,31 @@ public static final double DELTA_LNG_75 = 0.00075; public static final double DELTA_LAT_75 = 0.00075; + /** + * 西路社区:116.0497949886485,27.7523090448274 + * 永胜、中山社区:116.04801256908105,27.764489266672403 + * 城北社区:116.05083134025335,27.78274489130171 + * 一木社区:116.06179579161108,27.780238298884917 + * 新街社区:116.0569392645266,27.775902775818285 + * 南道社区:116.05398381594571,27.765387699087427 + * 胜利社区:116.05763011146338,27.758979599138858 + * 黄家社区:116.06998477480374,27.766637205647783 + * 中大社区:116.06510639190675,27.752823008396483 + * 中大、子正社区:116.08546817209574,27.758020310248185 + * 子正、高新区:116.11514568328859,27.774506608946538 + */ + public static final double[] XILU = {116.0497949886485, 27.7523090448274}; + public static final double[] YONG_ZHONG = {116.04801256908105, 27.764489266672403}; + public static final double[] CHENGBEI = {116.05083134025335, 27.78274489130171}; + public static final double[] YIMU = {116.06179579161108, 27.780238298884917}; + public static final double[] XINJIE = {116.0569392645266, 27.775902775818285}; + public static final double[] NANDAO = {116.05398381594571, 27.765387699087427}; + public static final double[] SHENGLI = {116.05763011146338, 27.758979599138858}; + public static final double[] HUANGJIA = {116.06998477480374, 27.766637205647783}; + public static final double[] ZHONGDA = {116.06510639190675, 27.752823008396483}; + public static final double[] ZHONG_ZI = {116.08546817209574, 27.758020310248185}; + public static final double[] ZI_GAO = {116.11514568328859, 27.774506608946538}; + //单独网络请求接口名 public static final String SHOP_DETAIL = "/shop/merchant/detail?merchantId="; public static final String SHOP_PUNISH_LIST = "/shop/punish/listByMerchant?merchantId="; diff --git a/app/src/main/java/com/casic/dcms/utils/StringHelper.java b/app/src/main/java/com/casic/dcms/utils/StringHelper.java index a7cb679..df96c00 100644 --- a/app/src/main/java/com/casic/dcms/utils/StringHelper.java +++ b/app/src/main/java/com/casic/dcms/utils/StringHelper.java @@ -1,5 +1,6 @@ package com.casic.dcms.utils; +import android.content.res.AssetManager; import android.text.TextUtils; import android.util.Log; @@ -11,6 +12,9 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -206,6 +210,30 @@ } /** + * 获取本地Asserts文件内容 + */ + public static String getAssetsData(AssetManager manager, String fileName) { + try { + InputStreamReader inputStreamReader = new InputStreamReader(manager.open(fileName)); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + StringBuilder data = new StringBuilder(); + String s; + try { + while ((s = bufferedReader.readLine()) != null) { + data.append(s); + } + Log.d(TAG, "getAssetsData: " + data); + return data.toString(); + } catch (IOException e) { + e.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** * 三包处罚转换 */ public static String StringToType(String s) { diff --git a/app/src/main/res/layout/fragment_mine.xml b/app/src/main/res/layout/fragment_mine.xml index 7f4dafc..ee739c4 100644 --- a/app/src/main/res/layout/fragment_mine.xml +++ b/app/src/main/res/layout/fragment_mine.xml @@ -99,30 +99,6 @@ - - - - - - - - - + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt new file mode 100644 index 0000000..a33bb4e --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt @@ -0,0 +1,183 @@ +package com.casic.dcms.ui.fragment + +import android.app.ProgressDialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.casic.dcms.BuildConfig +import com.casic.dcms.R +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.bean.NewVersionBean +import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl +import com.casic.dcms.mvp.presenter.UpdatePresenterImpl +import com.casic.dcms.mvp.view.ILoginOutView +import com.casic.dcms.mvp.view.IUpdateVersionView +import com.casic.dcms.ui.ChangePasswordActivity +import com.casic.dcms.ui.HelpfulActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.ui.UserInfoActivity +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IDownloadListener +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MinePageFragment : BaseFragment(), IUpdateVersionView, ILoginOutView { + + private var clipboardManager: ClipboardManager? = null + private lateinit var loginOutPresenter: LoginOutPresenterImpl + private lateinit var updatePresenter: UpdatePresenterImpl + private lateinit var progressDialog: ProgressDialog + + override fun initLayoutView(): Int = R.layout.fragment_mine + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deviceIdView!!.text = OtherUtils.obtainSimCardSerialNumber(context) + versionCodeView!!.text = BuildConfig.VERSION_NAME + loginOutPresenter = LoginOutPresenterImpl(this) + val isAutoLogin = SaveKeyValues.getValue("autoLogin", false) as Boolean + autoLoginSwitch!!.isChecked = isAutoLogin + updatePresenter = UpdatePresenterImpl(this) + clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + + //下载进度条 + progressDialog = ProgressDialog(context) + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + progressDialog.setProgressDrawable(context?.resources!!.getDrawable(R.drawable.bg_progress)) + progressDialog.setCanceledOnTouchOutside(false) + } + + override fun initEvent() { + userNameLayout.setOnClickListener { + startActivity(Intent(context, UserInfoActivity::class.java)) + } + passwordLayout.setOnClickListener { + startActivity(Intent(context, ChangePasswordActivity::class.java)) + } + helpfulLayout.setOnClickListener { + startActivity(Intent(context, HelpfulActivity::class.java)) + } + autoLoginSwitch!!.setOnCheckedChangeListener { buttonView, isChecked -> + SaveKeyValues.putValue("autoLogin", isChecked) + } + copyView.setOnClickListener { + val clipData = ClipData.newPlainText("deviceId", deviceIdView!!.text.toString()) + clipboardManager!!.setPrimaryClip(clipData) + ToastHelper.showToast("复制成功", ToastHelper.SUCCESS) + } + updateVersionView.setOnClickListener { updatePresenter.onReadyRetrofitRequest() } + + loginOutButton!!.setChangeAlphaWhenPress(true) + loginOutButton.setOnClickListener { + MessageDialogBuilder(context) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + loginOutPresenter.onReadyRetrofitRequest() + }.create().show() + } + } + + override fun obtainLoginOutResult(resultBean: ActionResultBean) { + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + } + + override fun showProgress() { + OtherUtils.showLoadingDialog(context, "请求中,请稍后") + } + + override fun hideProgress() { + OtherUtils.dismissLoadingDialog() + } + + override fun obtainVersionResult(resultBean: NewVersionBean) { +// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val data = resultBean.data + val version = data.version + if (BuildConfig.VERSION_NAME == version) { + ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO) + } else { + val downloadUrl = StringHelper.appendDownloadUrl(data.downloadUrl) + //http://111.198.10.15:11409/static/app/v1.1.0.0.apk + MessageDialogBuilder(context) + .setTitle("版本更新") + .setMessage("确定下载新版本吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定", QMUIDialogAction.ActionListener { dialog, index -> + dialog.dismiss() + //下载新版本 + progressDialog.setMessage("下载新版本中...") + progressDialog.show() + if (progressDialog.progress != 0) { + progressDialog.progress = 0 //防止下载到中途却卡住无法再进行下载 + return@ActionListener + } + downloadApk(downloadUrl) + }).create().show() + } + } + } + + //下载apk + private fun downloadApk(url: String) { + FileUtils.downloadFile(url, object : IDownloadListener { + override fun onDownloadStart(totalBytes: Long) { + progressDialog.max = totalBytes.toInt() + } + + override fun onProgressChanged(currentBytes: Long) { + progressDialog.progress = currentBytes.toInt() + } + + override fun onDownloadEnd(file: File) { + progressDialog.progress = 0 //防止下载完成却卡住的情况 + progressDialog.dismiss() + installApk(file) + } + }) + } + + //安装apk文件 + private fun installApk(apk: File) { + val intent = Intent(Intent.ACTION_VIEW) + val data: Uri + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //判断版本大于等于7.0 + // 通过FileProvider创建一个content类型的Uri + data = FileProvider.getUriForFile( + requireContext(), + "com.casic.dcms.install.fileProvider", apk + ) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 给目标应用一个临时授权 + } else { + data = Uri.fromFile(apk) + } + intent.setDataAndType(data, "application/vnd.android.package-archive") + requireContext().startActivity(intent) + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } + + override fun onDestroyView() { + super.onDestroyView() + loginOutPresenter.disposeRetrofitRequest() + updatePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java deleted file mode 100644 index e2488fc..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -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.greendao.NoticeBeanDao; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.igexin.sdk.message.GTTransmitMessage; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; - -import org.jetbrains.annotations.NotNull; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class NoticePageFragment extends BaseFragment { - - private static final String TAG = "NoticePageFragment"; - @BindView(R.id.swipeRecyclerView) - RecyclerView swipeRecyclerView; - - private Context context; - private List noticeBeans = new ArrayList<>(); - private SwipeViewAdapter swipeViewAdapter; - private DaoSession daoSession; - private static WeakReferenceHandler weakReferenceHandler; - - @Override - protected int initLayoutView() { - return R.layout.fragment_notice; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - daoSession = BaseApplication.getDaoSession(); - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeans = daoSession.queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeBeanDao.Properties.PushDate)//按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - - weakReferenceHandler = new WeakReferenceHandler(this); - } - - @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - int position = viewHolder.getAdapterPosition(); - daoSession.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - 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); - } - }); - swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - daoSession.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - - @Override - public void handleMessage(@NotNull Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == Constant.PUSH_MESSAGE_DATA) { - NoticeBean noticeBean = (NoticeBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean);//新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt new file mode 100644 index 0000000..05e6ddb --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt @@ -0,0 +1,152 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.os.Handler +import android.os.Message +import android.text.TextUtils +import android.util.Log +import android.view.ViewGroup +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +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.NoticeBeanDao +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction +import com.qmuiteam.qmui.recyclerView.QMUISwipeAction +import kotlinx.android.synthetic.main.fragment_notice.* +import java.lang.ref.WeakReference +import java.util.* + +class NoticePageFragment : BaseFragment() { + + private lateinit var noticeBeanDao: NoticeBeanDao + private lateinit var swipeViewAdapter: SwipeViewAdapter + private var noticeBeans: MutableList = ArrayList() + + override fun initLayoutView(): Int = R.layout.fragment_notice + + override fun setupTopBarLayout() { + + } + + override fun initData() { + swipeViewAdapter = SwipeViewAdapter(context) + //根据loginName加载历史数据 + val account = StringHelper.getUserAccount() + if (TextUtils.isEmpty(account)) { + return + } + noticeBeanDao = BaseApplication.getDaoSession().noticeBeanDao + noticeBeans = noticeBeanDao.queryBuilder() + .where(NoticeBeanDao.Properties.UserAccount.eq(account)) + .orderDesc(NoticeBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 + .list() + swipeViewAdapter.setData(noticeBeans) + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initEvent() { + val swipeAction = QMUIRVItemSwipeAction(true, object : QMUIRVItemSwipeAction.Callback() { + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = viewHolder.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + + override fun getSwipeDirection( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ): Int { + return QMUIRVItemSwipeAction.SWIPE_LEFT + } + + override fun onClickAction( + swipeAction: QMUIRVItemSwipeAction, + selected: RecyclerView.ViewHolder, + action: QMUISwipeAction + ) { + super.onClickAction(swipeAction, selected, action) + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = selected.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + }) + swipeAction.attachToRecyclerView(swipeRecyclerView) + swipeRecyclerView!!.layoutManager = object : LinearLayoutManager(context) { + override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams { + return RecyclerView.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + } + swipeRecyclerView!!.addItemDecoration( + DividerItemDecoration( + context, + DividerItemDecoration.VERTICAL + ) + ) + swipeRecyclerView!!.adapter = swipeViewAdapter + swipeViewAdapter.setOnItemClickListener { position -> //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + + //点击之后之后,未读消息变为已读消息 + val noticeBean = noticeBeans[position] + noticeBean.isRead = "0" + noticeBeanDao.update(noticeBean) + swipeViewAdapter.notifyDataSetChanged() + val caseId = noticeBeans[position].caseId + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + } + + private class WeakReferenceHandler(fragment: NoticePageFragment) : Handler() { + private val reference: WeakReference = WeakReference(fragment) + override fun handleMessage(msg: Message) { + val noticePageFragment: NoticePageFragment? + try { + noticePageFragment = reference.get() + val noticeBeans = noticePageFragment!!.noticeBeans + if (msg.what == Constant.PUSH_MESSAGE_DATA) { + val noticeBean = msg.obj as NoticeBean + Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.caseId) + noticeBeans.add(0, noticeBean) //新消息永远放到第一个 + //更新数据 + noticePageFragment.swipeViewAdapter.setData(noticeBeans) + } + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + + } + + companion object { + private const val TAG = "NoticePageFragment" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java deleted file mode 100644 index 13aa09b..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.text.TextUtils; -import android.view.View; -import android.widget.ExpandableListView; - -import com.casic.dcms.R; -import com.casic.dcms.adapter.DeptExpandableAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.DeptTreeBean; -import com.casic.dcms.bean.PersonBean; -import com.casic.dcms.bean.PhoneBookBean; -import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl; -import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl; -import com.casic.dcms.mvp.view.IDeptTreeView; -import com.casic.dcms.mvp.view.IPhoneBookView; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; - -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class PhonePageFragment extends BaseFragment implements IDeptTreeView, IPhoneBookView { - - private static final String TAG = "PhonePageFragment"; - - @BindView(R.id.deptTreeView) - ExpandableListView deptTreeView; - - private Context context; - private DeptTreePresenterImpl deptTreePresenter; - private PhoneBookPresenterImpl phoneBookPresenter; - private List deptList = new ArrayList<>();//部门名集合 - private List> deptAndPersons = new ArrayList<>();//个人信息集合的集合 - private DeptExpandableAdapter expandableAdapter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_phone; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deptTreePresenter = new DeptTreePresenterImpl(this); - deptTreePresenter.onReadyRetrofitRequest("0"); - phoneBookPresenter = new PhoneBookPresenterImpl(this); - expandableAdapter = new DeptExpandableAdapter(context); - } - - @Override - protected void initEvent() { - - } - - - @Override - public void obtainDeptTreeResult(DeptTreeBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - //先获取部门树,在往树结构里面加人 - if (resultBean.isSuccess()) { - List listBeans = resultBean.getData().getList(); - deptList.clear(); - for (DeptTreeBean.DataBean.ListBean bean : listBeans) { - deptList.add(bean.getName()); - } - if (deptList.size() > 0) { - phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().getDeptId()); - } - } - } - - @Override - public void obtainPhoneBookResult(PhoneBookBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - List dataBeans = resultBean.getData(); - deptAndPersons.clear(); - for (String title : deptList) { - List beanList = new ArrayList<>(); - for (PhoneBookBean.DataBean dataBean : dataBeans) { - if (title.equals(dataBean.getDeptName())) { - PersonBean personBean = new PersonBean(); - personBean.setPersonDept(dataBean.getDeptName()); - personBean.setPersonName(dataBean.getName()); - personBean.setPersonPhone(dataBean.getPhone()); - - beanList.add(personBean); - } - } - deptAndPersons.add(beanList); - } - //展示部门树以及人员 - expandableAdapter.setData(deptList, deptAndPersons); - deptTreeView.setAdapter(expandableAdapter); - //默认展开数据 - for (int i = 0; i < expandableAdapter.getGroupCount(); i++) { - deptTreeView.expandGroup(i); - } - deptTreeView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { - @Override - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - PersonBean personBean = deptAndPersons.get(groupPosition).get(childPosition); - callPhone(personBean.getPersonName(), personBean.getPersonPhone()); - return true; - } - }); - } - } - - /** - * 直接呼叫电话 - */ - private void callPhone(String personName, String personPhone) { - if (TextUtils.isEmpty(personPhone)) { - ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR); - return; - } - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("提示") - .setMessage("是否确定拨打[" + personName + "]的电话?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_CALL); - intent.setData(Uri.parse("tel:" + personPhone)); - startActivity(intent); - } - }) - .create().show(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (deptTreePresenter != null) { - deptTreePresenter.disposeRetrofitRequest(); - } - if (phoneBookPresenter != null) { - phoneBookPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt new file mode 100644 index 0000000..e606857 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt @@ -0,0 +1,124 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.net.Uri +import android.text.TextUtils +import com.casic.dcms.R +import com.casic.dcms.adapter.DeptExpandableAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.DeptTreeBean +import com.casic.dcms.bean.PersonBean +import com.casic.dcms.bean.PhoneBookBean +import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl +import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl +import com.casic.dcms.mvp.view.IDeptTreeView +import com.casic.dcms.mvp.view.IPhoneBookView +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.fragment_phone.* +import java.util.* + +class PhonePageFragment : BaseFragment(), IDeptTreeView, IPhoneBookView { + + private lateinit var deptTreePresenter: DeptTreePresenterImpl + private lateinit var phoneBookPresenter: PhoneBookPresenterImpl + private lateinit var expandableAdapter: DeptExpandableAdapter + private val deptList: MutableList = ArrayList() //部门名集合 + private val deptAndPersons: MutableList> = ArrayList() //个人信息集合的集合 + + override fun initLayoutView(): Int { + return R.layout.fragment_phone + } + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deptTreePresenter = DeptTreePresenterImpl(this) + deptTreePresenter.onReadyRetrofitRequest("0") + phoneBookPresenter = PhoneBookPresenterImpl(this) + expandableAdapter = DeptExpandableAdapter(context) + } + + override fun initEvent() {} + + override fun obtainDeptTreeResult(resultBean: DeptTreeBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + //先获取部门树,在往树结构里面加人 + if (resultBean.isSuccess) { + val listBeans = resultBean.data.list + deptList.clear() + for (bean in listBeans) { + deptList.add(bean.name) + } + if (deptList.size > 0) { + phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().deptId) + } + } + } + + override fun obtainPhoneBookResult(resultBean: PhoneBookBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val dataBeans = resultBean.data + deptAndPersons.clear() + for (title in deptList) { + val beanList: MutableList = ArrayList() + for (dataBean in dataBeans) { + if (title == dataBean.deptName) { + val personBean = PersonBean() + personBean.personDept = dataBean.deptName + personBean.personName = dataBean.name + personBean.personPhone = dataBean.phone + beanList.add(personBean) + } + } + deptAndPersons.add(beanList) + } + //展示部门树以及人员 + expandableAdapter.setData(deptList, deptAndPersons) + deptTreeView.setAdapter(expandableAdapter) + //默认展开数据 + for (i in 0 until expandableAdapter.groupCount) { + deptTreeView.expandGroup(i) + } + deptTreeView.setOnChildClickListener { parent, v, groupPosition, childPosition, id -> + val personBean = deptAndPersons[groupPosition][childPosition] + callPhone(personBean.personName, personBean.personPhone) + true + } + } + } + + /** + * 直接呼叫电话 + */ + private fun callPhone(personName: String, personPhone: String) { + if (TextUtils.isEmpty(personPhone)) { + ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR) + return + } + MessageDialogBuilder(context) + .setTitle("提示") + .setMessage("是否确定拨打[$personName]的电话?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + val intent = Intent() + intent.action = Intent.ACTION_CALL + intent.data = Uri.parse("tel:$personPhone") + startActivity(intent) + } + .create().show() + } + + override fun onDestroyView() { + super.onDestroyView() + deptTreePresenter.disposeRetrofitRequest() + phoneBookPresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/Constant.java b/app/src/main/java/com/casic/dcms/utils/Constant.java index 9bc9aa1..e41c903 100644 --- a/app/src/main/java/com/casic/dcms/utils/Constant.java +++ b/app/src/main/java/com/casic/dcms/utils/Constant.java @@ -81,6 +81,31 @@ public static final double DELTA_LNG_75 = 0.00075; public static final double DELTA_LAT_75 = 0.00075; + /** + * 西路社区:116.0497949886485,27.7523090448274 + * 永胜、中山社区:116.04801256908105,27.764489266672403 + * 城北社区:116.05083134025335,27.78274489130171 + * 一木社区:116.06179579161108,27.780238298884917 + * 新街社区:116.0569392645266,27.775902775818285 + * 南道社区:116.05398381594571,27.765387699087427 + * 胜利社区:116.05763011146338,27.758979599138858 + * 黄家社区:116.06998477480374,27.766637205647783 + * 中大社区:116.06510639190675,27.752823008396483 + * 中大、子正社区:116.08546817209574,27.758020310248185 + * 子正、高新区:116.11514568328859,27.774506608946538 + */ + public static final double[] XILU = {116.0497949886485, 27.7523090448274}; + public static final double[] YONG_ZHONG = {116.04801256908105, 27.764489266672403}; + public static final double[] CHENGBEI = {116.05083134025335, 27.78274489130171}; + public static final double[] YIMU = {116.06179579161108, 27.780238298884917}; + public static final double[] XINJIE = {116.0569392645266, 27.775902775818285}; + public static final double[] NANDAO = {116.05398381594571, 27.765387699087427}; + public static final double[] SHENGLI = {116.05763011146338, 27.758979599138858}; + public static final double[] HUANGJIA = {116.06998477480374, 27.766637205647783}; + public static final double[] ZHONGDA = {116.06510639190675, 27.752823008396483}; + public static final double[] ZHONG_ZI = {116.08546817209574, 27.758020310248185}; + public static final double[] ZI_GAO = {116.11514568328859, 27.774506608946538}; + //单独网络请求接口名 public static final String SHOP_DETAIL = "/shop/merchant/detail?merchantId="; public static final String SHOP_PUNISH_LIST = "/shop/punish/listByMerchant?merchantId="; diff --git a/app/src/main/java/com/casic/dcms/utils/StringHelper.java b/app/src/main/java/com/casic/dcms/utils/StringHelper.java index a7cb679..df96c00 100644 --- a/app/src/main/java/com/casic/dcms/utils/StringHelper.java +++ b/app/src/main/java/com/casic/dcms/utils/StringHelper.java @@ -1,5 +1,6 @@ package com.casic.dcms.utils; +import android.content.res.AssetManager; import android.text.TextUtils; import android.util.Log; @@ -11,6 +12,9 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -206,6 +210,30 @@ } /** + * 获取本地Asserts文件内容 + */ + public static String getAssetsData(AssetManager manager, String fileName) { + try { + InputStreamReader inputStreamReader = new InputStreamReader(manager.open(fileName)); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + StringBuilder data = new StringBuilder(); + String s; + try { + while ((s = bufferedReader.readLine()) != null) { + data.append(s); + } + Log.d(TAG, "getAssetsData: " + data); + return data.toString(); + } catch (IOException e) { + e.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** * 三包处罚转换 */ public static String StringToType(String s) { diff --git a/app/src/main/res/layout/fragment_mine.xml b/app/src/main/res/layout/fragment_mine.xml index 7f4dafc..ee739c4 100644 --- a/app/src/main/res/layout/fragment_mine.xml +++ b/app/src/main/res/layout/fragment_mine.xml @@ -99,30 +99,6 @@ - - - - - - - - - + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3b94b82..73a8cde 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -40,11 +42,13 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' //Google官方授权框架 - implementation 'pub.devrel:easypermissions:1.3.0' + implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 implementation 'com.qmuiteam:qmui:2.0.0-alpha10' implementation 'com.qmuiteam:arch:0.3.1' diff --git a/app/src/main/assets/enevlop.json b/app/src/main/assets/enevlop.json new file mode 100644 index 0000000..9edbbcb --- /dev/null +++ b/app/src/main/assets/enevlop.json @@ -0,0 +1,145 @@ +[ + { + "community": "西路社区", + "centerPoint": { + "lng": 116.0497949886485, + "lat": 27.7523090448274 + }, + "enevlop": { + "x_min": 116.04215037077668, + "y_min": 27.74572694231917, + "x_max": 116.05258567258718, + "y_max": 27.751715541888828 + } + }, + { + "community": "永胜、中山社区", + "centerPoint": { + "lng": 116.04801256908105, + "lat": 27.764489266672403 + }, + "enevlop": { + "x_min": 116.04242730885747, + "y_min": 27.764270421738438, + "x_max": 116.05148244649175, + "y_max": 27.76476409004304 + } + }, + { + "community": "城北社区", + "centerPoint": { + "lng": 116.05083134025335, + "lat": 27.78274489130171 + }, + "enevlop": { + "x_min": 116.04841433465482, + "y_min": 27.782856200136784, + "x_max": 116.05330668389799, + "y_max": 27.78369149478135 + } + }, + { + "community": "一木社区", + "centerPoint": { + "lng": 116.06179579161108, + "lat": 27.780238298884917 + }, + "enevlop": { + "x_min": 116.05053042992951, + "y_min": 27.779025657246244, + "x_max": 116.07632255181672, + "y_max": 27.778342205512264 + } + }, + { + "community": "新街社区", + "centerPoint": { + "lng": 116.0569392645266, + "lat": 27.775902775818285 + }, + "enevlop": { + "x_min": 116.05043361894789, + "y_min": 27.770891516966916, + "x_max": 116.0603256057948, + "y_max": 27.775239253936967 + } + }, + { + "community": "南道社区", + "centerPoint": { + "lng": 116.05398381594571, + "lat": 27.765387699087427 + }, + "enevlop": { + "x_min": 116.05208726366983, + "y_min": 27.763851866249375, + "x_max": 116.05628760298715, + "y_max": 27.763975284010094 + } + }, + { + "community": "胜利社区", + "centerPoint": { + "lng": 116.05763011146338, + "lat": 27.758979599138858 + }, + "enevlop": { + "x_min": 116.05565558653326, + "y_min": 27.75876823458353, + "x_max": 116.0605801222846, + "y_max": 27.75873025808618 + } + }, + { + "community": "黄家社区", + "centerPoint": { + "lng": 116.06998477480374, + "lat": 27.766637205647783 + }, + "enevlop": { + "x_min": 116.06068250723185, + "y_min": 27.76391878554235, + "x_max": 116.06978056021036, + "y_max": 27.766709889745304 + } + }, + { + "community": "中大社区", + "centerPoint": { + "lng": 116.06510639190675, + "lat": 27.752823008396483 + }, + "enevlop": { + "x_min": 116.05693135410549, + "y_min": 27.750294437422138, + "x_max": 116.07602868229152, + "y_max": 27.751623709933934 + } + }, + { + "community": "中大、子正社区", + "centerPoint": { + "lng": 116.08546817209574, + "lat": 27.758020310248185 + }, + "enevlop": { + "x_min": 116.0723949596286, + "y_min": 27.75715218197985, + "x_max": 116.09925996512176, + "y_max": 27.760456135581983 + } + }, + { + "community": "子正、高新区", + "centerPoint": { + "lng": 116.11514568328859, + "lat": 27.774506608946538 + }, + "enevlop": { + "x_min": 116.08997080475093, + "y_min": 27.770202451750833, + "x_max": 116.14490244537593, + "y_max": 27.778480142080515 + } + } +] diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index e8f9ad7..70d598e 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -16,7 +16,7 @@ public class BaseApplication extends Application { - private static DaoSession daoSession, streetLightDaoSession; + private static DaoSession daoSession; private volatile static BaseApplication instance; @Override @@ -33,7 +33,6 @@ //个推初始化 com.igexin.sdk.PushManager.getInstance().initialize(this); initDataBase(); - initStreetLightDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } @@ -52,7 +51,7 @@ } private void initDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "Notification.db"); + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "CityAdminister.db"); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); @@ -61,15 +60,4 @@ public static DaoSession getDaoSession() { return daoSession; } - - private void initStreetLightDataBase() { - DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "StreetLight.db"); - SQLiteDatabase db = helper.getWritableDatabase(); - DaoMaster daoMaster = new DaoMaster(db); - streetLightDaoSession = daoMaster.newSession(); - } - - public static DaoSession getStreetLightDaoSession() { - return streetLightDaoSession; - } } diff --git a/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java new file mode 100644 index 0000000..1bd72c5 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/bean/CommunityEnevlopBean.java @@ -0,0 +1,110 @@ +package com.casic.dcms.bean; + +public class CommunityEnevlopBean { + + /** + * community : 西路社区 + * centerPoint : {"lng":116.0497949886485,"lat":27.7523090448274} + * enevlop : {"x_min":116.04140203446151,"y_min":27.753370580776277,"x_max":116.05680864304304,"y_max":27.753712385601723} + */ + + private String community; + private CenterPointBean centerPoint; + private EnevlopBean enevlop; + + public String getCommunity() { + return community; + } + + public void setCommunity(String community) { + this.community = community; + } + + public CenterPointBean getCenterPoint() { + return centerPoint; + } + + public void setCenterPoint(CenterPointBean centerPoint) { + this.centerPoint = centerPoint; + } + + public EnevlopBean getEnevlop() { + return enevlop; + } + + public void setEnevlop(EnevlopBean enevlop) { + this.enevlop = enevlop; + } + + public static class CenterPointBean { + /** + * lng : 116.0497949886485 + * lat : 27.7523090448274 + */ + + private double lng; + private double lat; + + public double getLng() { + return lng; + } + + public void setLng(double lng) { + this.lng = lng; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + } + + public static class EnevlopBean { + /** + * x_min : 116.04140203446151 + * y_min : 27.753370580776277 + * x_max : 116.05680864304304 + * y_max : 27.753712385601723 + */ + + private double x_min; + private double y_min; + private double x_max; + private double y_max; + + public double getX_min() { + return x_min; + } + + public void setX_min(double x_min) { + this.x_min = x_min; + } + + public double getY_min() { + return y_min; + } + + public void setY_min(double y_min) { + this.y_min = y_min; + } + + public double getX_max() { + return x_max; + } + + public void setX_max(double x_max) { + this.x_max = x_max; + } + + public double getY_max() { + return y_max; + } + + public void setY_max(double y_max) { + this.y_max = y_max; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java deleted file mode 100644 index aac6084..0000000 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.casic.dcms.service; - -import android.content.Context; -import android.content.Intent; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; - -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.PushResultBean; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.igexin.sdk.GTIntentService; -import com.igexin.sdk.message.GTCmdMessage; -import com.igexin.sdk.message.GTNotificationMessage; -import com.igexin.sdk.message.GTTransmitMessage; - -/** - * @author : Pengxh - * @time : 2021/4/16 16:16 - * @email : 290677893@qq.com - **/ -public class GeTuiIntentService extends GTIntentService { - private static final String TAG = "GeTuiIntentService"; - - @Override - public void onReceiveServicePid(Context context, int pid) { - - } - - // 处理透传消息 - @Override - public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - * */ - Log.d(TAG, "onReceiveMessageData -> " + "\r\nplayload = " + new String(msg.getPayload())); - - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - NoticeBean noticeBean = new NoticeBean(); - noticeBean.setUserAccount(StringHelper.getUserAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - - //存本地一份 - BaseApplication.getDaoSession().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = Constant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); - } - - // 接收 cid - @Override - public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> " + "clientid = " + clientid); - //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = Constant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = " + clientid); - } - } - - // cid 离线上线通知 - @Override - public void onReceiveOnlineState(Context context, boolean online) { - - } - - // 各种事件处理回执 - @Override - public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { -// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); - } - - // 通知到达,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage message) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); - } - - // 通知点击,只有个推通道下发的通知会回调此方法 - @Override - public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); - String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt new file mode 100644 index 0000000..fc0bcf6 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.kt @@ -0,0 +1,118 @@ +package com.casic.dcms.service + +import android.content.Context +import android.content.Intent +import android.os.Message +import android.text.TextUtils +import android.util.Log +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.bean.NoticeBean +import com.casic.dcms.bean.PushResultBean +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.TimeOrDateUtil +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.igexin.sdk.GTIntentService +import com.igexin.sdk.message.GTCmdMessage +import com.igexin.sdk.message.GTNotificationMessage +import com.igexin.sdk.message.GTTransmitMessage + +/** + * @author : Pengxh + * @time : 2021/4/16 16:16 + * @email : 290677893@qq.com + */ +class GeTuiIntentService : GTIntentService() { + override fun onReceiveServicePid(context: Context, pid: Int) {} + + // 处理透传消息 + override fun onReceiveMessageData(context: Context, msg: GTTransmitMessage) { + /** + * appid = DR9oeLL9va6aG3DYXy2w39 + * taskid = TEST_0515_d4689edeff9808959f10365895682f6f + * messageid = bd9c2465afd5464fb99368a579fd3fc8 + * pkg = com.casic.dcms + * cid = 9e85018b1972d664d9e86e9a6d03b4a7 + * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} + */ + val gson = Gson() + val messageContent = String(msg.payload) + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val noticeBean = NoticeBean() + noticeBean.userAccount = StringHelper.getUserAccount() + noticeBean.caseId = resultBean.data.id + noticeBean.title = resultBean.title + noticeBean.content = resultBean.content + noticeBean.type = resultBean.type + noticeBean.pushDate = TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis()) + noticeBean.isRead = "1" + + //存本地一份 + BaseApplication.getDaoSession().noticeBeanDao.insert(noticeBean) + + //创建通知栏 + val msgNotice = Message.obtain() + msgNotice.what = Constant.PUSH_CREATE_NOTIFICATION + msgNotice.obj = noticeBean + sendMessage(msgNotice) + + //发送消息更新界面 + val msgBean = Message.obtain() + msgBean.what = Constant.PUSH_MESSAGE_DATA + msgBean.obj = noticeBean + NoticePageFragment.sendMessage(msgBean) + } + + // 接收 cid + override fun onReceiveClientId(context: Context, clientid: String) { + Log.d(TAG, "onReceiveClientId -> clientid = $clientid") + //通知MainActivity注册个推服务 + if (!TextUtils.isEmpty(clientid)) { + val msg = Message.obtain() + msg.what = Constant.PUSH_REGISTER + msg.obj = clientid + sendMessage(msg) + } else { + Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid") + } + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context, online: Boolean) {} + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context, cmdMessage: GTCmdMessage) { +// Log.d(TAG, "onReceiveCommandResult -> " + cmdMessage); + } + + // 通知到达,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageArrived(context: Context, message: GTNotificationMessage) { + Log.d(TAG, "onNotificationMessageArrived: 通知到达") + } + + // 通知点击,只有个推通道下发的通知会回调此方法 + override fun onNotificationMessageClicked(context: Context, message: GTNotificationMessage) { + val gson = Gson() + val messageContent = message.content + val resultBean = gson.fromJson( + messageContent, + object : TypeToken() {}.type + ) + val caseId = resultBean.data.id + Log.d(TAG, "onNotificationMessageClicked: $caseId") + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + + companion object { + private const val TAG = "GeTuiIntentService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index 4758703..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.location.Location; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - public UploadLocationService() { - - } - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - - LocationHelper.obtainCurrentLocationByGD(this, new ILocationListener() { - @Override - public void onLocationGet(Location location) { - - } - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = Constant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt new file mode 100644 index 0000000..8525afa --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UploadLocationService.kt @@ -0,0 +1,47 @@ +package com.casic.dcms.service + +import android.app.Service +import android.content.Intent +import android.location.Location +import android.os.IBinder +import android.os.Message +import android.util.Log +import com.amap.api.location.AMapLocation +import com.casic.dcms.ui.MainActivity.Companion.sendMessage +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.LocationHelper +import com.casic.dcms.utils.NotificationHelper +import com.casic.dcms.utils.callback.ILocationListener + +class UploadLocationService : Service() { + override fun onCreate() { + super.onCreate() + val notificationHelper = NotificationHelper.getInstance(this) + val notification = notificationHelper.createKeepAlive() + startForeground(Int.MAX_VALUE, notification) + LocationHelper.obtainCurrentLocationByGD(this, object : ILocationListener { + override fun onLocationGet(location: Location) {} + + override fun onAMapLocationGet(aMapLocation: AMapLocation) { + Log.d(TAG, "onAMapLocationGet: UploadLocationService") + val message = Message.obtain() + message.what = Constant.UPLOAD_LOCATION + message.obj = aMapLocation + sendMessage(message) + } + }, false) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY + } + + override fun onBind(intent: Intent): IBinder? { + return null + } + + companion object { + private const val TAG = "UploadLocationService" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java deleted file mode 100644 index 12f7469..0000000 --- a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.casic.dcms.ui; - -import android.text.TextUtils; -import android.view.View; -import android.widget.EditText; - -import androidx.core.content.ContextCompat; - -import com.casic.dcms.R; -import com.casic.dcms.base.BaseActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl; -import com.casic.dcms.mvp.view.IChangePasswordView; -import com.casic.dcms.utils.AuthenticationHelper; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.RSAUtils; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.security.PublicKey; - -import butterknife.BindView; -import butterknife.OnClick; - -/** - * @author : Pengxh - * @time : 2021/4/14 13:20 - * @email : 290677893@qq.com - **/ -public class ChangePasswordActivity extends BaseActivity implements View.OnClickListener, IChangePasswordView { - - private static final String TAG = "ChangePasswordActivity"; - @BindView(R.id.topLayout) - QMUITopBarLayout topLayout; - @BindView(R.id.originalEditView) - EditText originalEditView; - @BindView(R.id.newEditView) - EditText newEditView; - @BindView(R.id.confirmEditView) - EditText confirmEditView; - @BindView(R.id.changePasswordButton) - QMUIRoundButton changePasswordButton; - private ChangePasswordPresenterImpl changePasswordPresenter; - - @Override - public int initLayoutView() { - return R.layout.activity_password; - } - - @Override - protected void setupTopBarLayout() { - topLayout.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)); - topLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)); - topLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - finish(); - } - }); - } - - @Override - public void initData() { - changePasswordPresenter = new ChangePasswordPresenterImpl(this); - } - - @Override - public void initEvent() { - changePasswordButton.setChangeAlphaWhenPress(true); - } - - @OnClick(R.id.changePasswordButton) - @Override - public void onClick(View v) { - String oldPassword = originalEditView.getText().toString(); - if (TextUtils.isEmpty(oldPassword)) { - ToastHelper.showToast("请先输入原密码", ToastHelper.WARING); - return; - } - String newPassword = newEditView.getText().toString(); - if (TextUtils.isEmpty(newPassword)) { - ToastHelper.showToast("请先输入新密码", ToastHelper.WARING); - return; - } - String confirmPassword = confirmEditView.getText().toString(); - if (TextUtils.isEmpty(confirmPassword)) { - ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING); - return; - } - if (!newPassword.equals(confirmPassword)) { - ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING); - return; - } - if (newPassword.length() < 6 || newPassword.length() > 12) { - ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING); - return; - } - if (!StringHelper.isLetterAndDigit(newPassword)) { - ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING); - return; - } - //数据校验OK,可以修改密码 - PublicKey publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()); - String oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.getBytes(), publicKey); - String newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.getBytes(), publicKey); - changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey); - } - - @Override - public void obtainChangePassResult(ActionResultBean resultBean) { - if (resultBean.isSuccess()) { - new QMUIDialog.MessageDialogBuilder(this) - .setTitle("温馨提示") - .setMessage("密码已修改成功,请重新登录") - .setCancelable(false) - .setCanceledOnTouchOutside(false) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - }).create().show(); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt new file mode 100644 index 0000000..ab25ee4 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/ChangePasswordActivity.kt @@ -0,0 +1,91 @@ +package com.casic.dcms.ui + +import android.text.TextUtils +import androidx.core.content.ContextCompat +import com.casic.dcms.R +import com.casic.dcms.base.BaseActivity +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.mvp.presenter.ChangePasswordPresenterImpl +import com.casic.dcms.mvp.view.IChangePasswordView +import com.casic.dcms.utils.* +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.activity_password.* +import kotlinx.android.synthetic.main.include_top_bar.* + +/** + * @author : Pengxh + * @time : 2021/4/14 13:20 + * @email : 290677893@qq.com + */ +class ChangePasswordActivity : BaseActivity(), IChangePasswordView { + + private lateinit var changePasswordPresenter: ChangePasswordPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_password + + override fun setupTopBarLayout() { + topLayout!!.setTitle("修改密码").setTextColor(ContextCompat.getColor(this, R.color.white)) + topLayout!!.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor)) + topLayout!!.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener { finish() } + } + + override fun initData() { + changePasswordPresenter = ChangePasswordPresenterImpl(this) + } + + override fun initEvent() { + changePasswordButton!!.setChangeAlphaWhenPress(true) + changePasswordButton.setOnClickListener { + val oldPassword = originalEditView!!.text.toString() + if (TextUtils.isEmpty(oldPassword)) { + ToastHelper.showToast("请先输入原密码", ToastHelper.WARING) + return@setOnClickListener + } + val newPassword = newEditView!!.text.toString() + if (TextUtils.isEmpty(newPassword)) { + ToastHelper.showToast("请先输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + val confirmPassword = confirmEditView!!.text.toString() + if (TextUtils.isEmpty(confirmPassword)) { + ToastHelper.showToast("请再次输入新密码", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword != confirmPassword) { + ToastHelper.showToast("新密码和确认密码输入不一致,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (newPassword.length < 6 || newPassword.length > 12) { + ToastHelper.showToast("新密码长度不正确,请重新输入", ToastHelper.WARING) + return@setOnClickListener + } + if (!StringHelper.isLetterAndDigit(newPassword)) { + ToastHelper.showToast("新密码请输入6-12位的数字字母组合", ToastHelper.WARING) + return@setOnClickListener + } + //数据校验OK,可以修改密码 + val publicKey = RSAUtils.keyStrToPublicKey(AuthenticationHelper.getPublicKey()) + val oldPassKey = RSAUtils.encryptDataByPublicKey(oldPassword.toByteArray(), publicKey) + val newPassKey = RSAUtils.encryptDataByPublicKey(newPassword.toByteArray(), publicKey) + changePasswordPresenter.onReadyRetrofitRequest(oldPassKey, newPassKey) + } + } + + override fun obtainChangePassResult(resultBean: ActionResultBean) { + if (resultBean.isSuccess) { + MessageDialogBuilder(this) + .setTitle("温馨提示") + .setMessage("密码已修改成功,请重新登录") + .setCancelable(false) + .setCanceledOnTouchOutside(false) + .addAction("确定") { dialog, index -> + dialog.dismiss() + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + }.create().show() + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.java b/app/src/main/java/com/casic/dcms/ui/MainActivity.java deleted file mode 100644 index 5a2a0fd..0000000 --- a/app/src/main/java/com/casic/dcms/ui/MainActivity.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.casic.dcms.ui; - -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Handler; -import android.os.Message; -import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.viewpager.widget.ViewPager; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.R; -import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.base.DoubleClickExitActivity; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.BridgeConfigBean; -import com.casic.dcms.bean.LayerConfigBean; -import com.casic.dcms.bean.MapConfigBean; -import com.casic.dcms.bean.NoticeBean; -import com.casic.dcms.bean.ToiletListBean; -import com.casic.dcms.greendao.NoticeBeanDao; -import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl; -import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl; -import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl; -import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl; -import com.casic.dcms.mvp.view.IMapConfigView; -import com.casic.dcms.mvp.view.IPushRegisterView; -import com.casic.dcms.mvp.view.IToiletListView; -import com.casic.dcms.mvp.view.IUploadPositionView; -import com.casic.dcms.service.UploadLocationService; -import com.casic.dcms.ui.fragment.HomePageFragment; -import com.casic.dcms.ui.fragment.MinePageFragment; -import com.casic.dcms.ui.fragment.NoticePageFragment; -import com.casic.dcms.ui.fragment.PhonePageFragment; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.HttpRequestHelper; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StatusBarColorUtil; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.callback.IHttpRequestListener; -import com.casic.dcms.widgets.NoScrollViewPager; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.gson.Gson; -import com.gyf.immersionbar.ImmersionBar; -import com.igexin.sdk.message.GTTransmitMessage; - -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; -import okhttp3.ResponseBody; - -public class MainActivity extends DoubleClickExitActivity implements IUploadPositionView, - IPushRegisterView, IMapConfigView, IToiletListView { - - private static final String TAG = "MainActivity"; - @BindView(R.id.pageTitleView) - TextView pageTitleView; - @BindView(R.id.mainViewPager) - NoScrollViewPager mainViewPager; - @BindView(R.id.bottomNavigation) - BottomNavigationView bottomNavigation; - @BindView(R.id.messageNumView) - TextView messageNumView; - - private MenuItem menuItem; - private List pageList; - private UploadPositionPresenterImpl uploadPositionPresenter; - private PushRegisterPresenterImpl registerPresenter; - private MapConfigPresenterImpl mapConfigPresenter; - private ToiletListPresenterImpl toiletListPresenter; - private String imei = ""; - private static WeakReferenceHandler weakReferenceHandler; - private Gson gson; - - @Override - public int initLayoutView() { - return R.layout.activity_main; - } - - @Override - protected void setupTopBarLayout() { - StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)); - ImmersionBar.with(this).statusBarDarkFont(false).init(); - pageTitleView.setText("首页"); - } - - @Override - public void initData() { - //个推初始化 - com.igexin.sdk.PushManager.getInstance().initialize(this); - weakReferenceHandler = new WeakReferenceHandler(this); - uploadPositionPresenter = new UploadPositionPresenterImpl(this); - registerPresenter = new PushRegisterPresenterImpl(this); - mapConfigPresenter = new MapConfigPresenterImpl(this); - toiletListPresenter = new ToiletListPresenterImpl(this); - gson = new Gson(); - //获取配置项 - obtainProjectConfig(); - //配置页面 - pageList = new ArrayList<>(); - pageList.add(new HomePageFragment()); - pageList.add(new PhonePageFragment()); - pageList.add(new NoticePageFragment()); - pageList.add(new MinePageFragment()); - - imei = OtherUtils.obtainSimCardSerialNumber(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); - } else { - startService(new Intent(this, UploadLocationService.class)); - } - updateMessageNumber(); - } - - private void obtainProjectConfig() { - //地图配置项 - mapConfigPresenter.onReadyRetrofitRequest(); - //桥梁数据 - HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List bridges = gson.fromJson(resultStr, BridgeConfigBean.class).getBridges(); - StringHelper.saveBridgeList(gson.toJson(bridges)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - //公厕数据 - toiletListPresenter.onReadyRetrofitRequest(); - //公厕图层ID - HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, new IHttpRequestListener() { - @Override - public void onSuccess(ResponseBody resultBean) { - try { - String resultStr = resultBean.string(); - List partsLayer = gson.fromJson(resultStr, LayerConfigBean.class).getPartsLayer(); - List childrenBeans = partsLayer.get(2).getChildren(); - StringHelper.saveToiletLayerID(String.valueOf(childrenBeans.get(0).getLayer())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onFailure(Throwable throwable) { - - } - }); - } - - @Override - public void initEvent() { - bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_home: - mainViewPager.setCurrentItem(0); - pageTitleView.setText("首页"); - break; - case R.id.navigation_phone: - mainViewPager.setCurrentItem(1); - pageTitleView.setText("通讯录"); - break; - case R.id.navigation_dashboard: - mainViewPager.setCurrentItem(2); - pageTitleView.setText("消息"); - break; - case R.id.navigation_mine: - mainViewPager.setCurrentItem(3); - pageTitleView.setText("我的"); - break; - default: - break; - } - return false; - } - }); - mainViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - if (menuItem != null) { - menuItem.setChecked(false); - } else { - bottomNavigation.getMenu().getItem(0).setChecked(false); - } - menuItem = bottomNavigation.getMenu().getItem(position); - menuItem.setChecked(true); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - MainPageAdapter mainPageAdapter = new MainPageAdapter(getSupportFragmentManager(), pageList); - mainViewPager.setAdapter(mainPageAdapter); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveClientId(Context, String)}页面调用 - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}页面调用 - * 供{@link com.casic.dcms.service.UploadLocationService#onCreate()}页面调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - /** - * 供{@link MinePageFragment#obtainLoginOutResult(ActionResultBean)}页面调用 - */ - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(MainActivity activity) { - reference = new WeakReference<>(activity); - } - - @Override - public void handleMessage(Message msg) { - MainActivity mainActivity = reference.get(); - switch (msg.what) { - case Constant.PUSH_REGISTER: - String clientId = (String) msg.obj; - Log.d(TAG, "注册个推Client: " + clientId); - mainActivity.registerPresenter.onReadyRetrofitRequest(clientId); - break; - case Constant.PUSH_CREATE_NOTIFICATION: - //显示小红点 - try { - mainActivity.updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - - NoticeBean noticeBean = (NoticeBean) msg.obj; - if (null == noticeBean) { - return; - } - NotificationHelper notificationHelper = NotificationHelper.getInstance(mainActivity); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class); - notificationHelper.push(1, notification); - break; - case Constant.MESSAGE_NUMBER: - mainActivity.updateMessageNumber(); - break; - case Constant.UPLOAD_LOCATION: - AMapLocation aMapLocation = (AMapLocation) msg.obj; - try { - double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - mainActivity.uploadPositionPresenter.onReadyRetrofitRequest(mainActivity.imei, - String.valueOf(gcjToWgs[1]), String.valueOf(gcjToWgs[0])); - } catch (NullPointerException e) { - e.printStackTrace(); - } - break; - case Constant.LOGIN_OUT: - Log.d(TAG, "退出登录"); - //回到登录页 - SaveKeyValues.putValue("autoLogin", false); - mainActivity.startActivity(new Intent(mainActivity, LoginActivity.class)); - mainActivity.finish(); - break; - } - } - } - - private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { - messageNumView.setVisibility(View.GONE); - } else { - messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { - messageNumView.setText("9+"); - } else { - messageNumView.setText(String.valueOf(size)); - } - } - } - - @Override - public void obtainUploadPositionResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainRegisterResult(ActionResultBean resultBean) { -// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); - } - - @Override - public void obtainMapConfig(MapConfigBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveMapConfigList(gson.toJson(resultBean.getData().getRows())); - } - } - - @Override - public void obtainToiletListData(ToiletListBean resultBean) { - if (resultBean.isSuccess()) { - StringHelper.saveToiletList(gson.toJson(resultBean.getData())); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (uploadPositionPresenter != null) { - uploadPositionPresenter.disposeRetrofitRequest(); - } - if (registerPresenter != null) { - registerPresenter.disposeRetrofitRequest(); - } - if (toiletListPresenter != null) { - toiletListPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/MainActivity.kt b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt new file mode 100644 index 0000000..11e423f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/MainActivity.kt @@ -0,0 +1,296 @@ +package com.casic.dcms.ui + +import android.content.Intent +import android.os.Build +import android.os.Handler +import android.os.Message +import android.util.Log +import android.view.MenuItem +import android.view.View +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager.OnPageChangeListener +import com.amap.api.location.AMapLocation +import com.casic.dcms.R +import com.casic.dcms.adapter.MainPageAdapter +import com.casic.dcms.base.BaseApplication +import com.casic.dcms.base.DoubleClickExitActivity +import com.casic.dcms.bean.* +import com.casic.dcms.greendao.NoticeBeanDao +import com.casic.dcms.mvp.presenter.MapConfigPresenterImpl +import com.casic.dcms.mvp.presenter.PushRegisterPresenterImpl +import com.casic.dcms.mvp.presenter.ToiletListPresenterImpl +import com.casic.dcms.mvp.presenter.UploadPositionPresenterImpl +import com.casic.dcms.mvp.view.IMapConfigView +import com.casic.dcms.mvp.view.IPushRegisterView +import com.casic.dcms.mvp.view.IToiletListView +import com.casic.dcms.mvp.view.IUploadPositionView +import com.casic.dcms.service.UploadLocationService +import com.casic.dcms.ui.fragment.HomePageFragment +import com.casic.dcms.ui.fragment.MinePageFragment +import com.casic.dcms.ui.fragment.NoticePageFragment +import com.casic.dcms.ui.fragment.PhonePageFragment +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IHttpRequestListener +import com.google.gson.Gson +import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager +import kotlinx.android.synthetic.main.activity_main.* +import okhttp3.ResponseBody +import java.io.IOException +import java.lang.ref.WeakReference +import java.util.* + +class MainActivity : DoubleClickExitActivity(), IUploadPositionView, IPushRegisterView, + IMapConfigView, IToiletListView { + + private var menuItem: MenuItem? = null + private var imei = "" + private var gson = Gson() + private var pageList: MutableList = ArrayList() + private lateinit var uploadPositionPresenter: UploadPositionPresenterImpl + private lateinit var registerPresenter: PushRegisterPresenterImpl + private lateinit var mapConfigPresenter: MapConfigPresenterImpl + private lateinit var toiletListPresenter: ToiletListPresenterImpl + + override fun initLayoutView(): Int = R.layout.activity_main + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.mainThemeColor)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + pageTitleView!!.text = "首页" + } + + override fun initData() { + //个推初始化 + PushManager.getInstance().initialize(this) + weakReferenceHandler = WeakReferenceHandler(this) + uploadPositionPresenter = UploadPositionPresenterImpl(this) + registerPresenter = PushRegisterPresenterImpl(this) + mapConfigPresenter = MapConfigPresenterImpl(this) + toiletListPresenter = ToiletListPresenterImpl(this) + //获取配置项 + obtainProjectConfig() + //配置页面 + pageList.add(HomePageFragment()) + pageList.add(PhonePageFragment()) + pageList.add(NoticePageFragment()) + pageList.add(MinePageFragment()) + imei = OtherUtils.obtainSimCardSerialNumber(this) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(Intent(this, UploadLocationService::class.java)) + } else { + startService(Intent(this, UploadLocationService::class.java)) + } + updateMessageNumber() + } + + private fun obtainProjectConfig() { + //地图配置项 + mapConfigPresenter.onReadyRetrofitRequest() + //桥梁数据 + HttpRequestHelper.doRequest(Constant.PROJECT_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val bridges = gson.fromJson(resultStr, BridgeConfigBean::class.java).bridges + StringHelper.saveBridgeList(gson.toJson(bridges)) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + //公厕数据 + toiletListPresenter.onReadyRetrofitRequest() + //公厕图层ID + HttpRequestHelper.doRequest(Constant.LAYER_CONFIG, object : IHttpRequestListener { + override fun onSuccess(resultBean: ResponseBody) { + try { + val resultStr = resultBean.string() + val partsLayer = + gson.fromJson(resultStr, LayerConfigBean::class.java).partsLayer + val childrenBeans = partsLayer[2].children + StringHelper.saveToiletLayerID(childrenBeans[0].layer.toString()) + } catch (e: IOException) { + e.printStackTrace() + } + } + + override fun onFailure(throwable: Throwable) {} + }) + } + + override fun initEvent() { + bottomNavigation!!.setOnNavigationItemSelectedListener { item -> + when (item.itemId) { + R.id.navigation_home -> { + mainViewPager!!.currentItem = 0 + pageTitleView!!.text = "首页" + } + R.id.navigation_phone -> { + mainViewPager!!.currentItem = 1 + pageTitleView!!.text = "通讯录" + } + R.id.navigation_dashboard -> { + mainViewPager!!.currentItem = 2 + pageTitleView!!.text = "消息" + } + R.id.navigation_mine -> { + mainViewPager!!.currentItem = 3 + pageTitleView!!.text = "我的" + } + } + false + } + mainViewPager!!.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + } + + override fun onPageSelected(position: Int) { + if (menuItem != null) { + menuItem!!.isChecked = false + } else { + bottomNavigation!!.menu.getItem(0).isChecked = false + } + menuItem = bottomNavigation!!.menu.getItem(position) + menuItem?.isChecked = true + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + val mainPageAdapter = MainPageAdapter(supportFragmentManager, pageList) + mainViewPager!!.adapter = mainPageAdapter + } + + private class WeakReferenceHandler(activity: MainActivity) : Handler() { + private val reference: WeakReference = WeakReference(activity) + override fun handleMessage(msg: Message) { + val mainActivity = reference.get() + when (msg.what) { + Constant.PUSH_REGISTER -> { + val clientId = msg.obj as String + Log.d(TAG, "注册个推Client: $clientId") + mainActivity!!.registerPresenter.onReadyRetrofitRequest(clientId) + } + Constant.PUSH_CREATE_NOTIFICATION -> { + //显示小红点 + try { + mainActivity!!.updateMessageNumber() + } catch (e: NullPointerException) { + e.printStackTrace() + } + val noticeBean = msg.obj as NoticeBean + val notificationHelper = NotificationHelper.getInstance(mainActivity) + val notification = notificationHelper.createDefault( + noticeBean.title, + noticeBean.content, + noticeBean.caseId, + CaseDetailActivity::class.java + ) + notificationHelper.push(1, notification) + } + Constant.MESSAGE_NUMBER -> mainActivity!!.updateMessageNumber() + Constant.UPLOAD_LOCATION -> { + val aMapLocation = msg.obj as AMapLocation + try { + val gcjToWgs = + LocationHelper.gcjToWgs(aMapLocation.longitude, aMapLocation.latitude) + mainActivity!!.uploadPositionPresenter.onReadyRetrofitRequest( + mainActivity.imei, + gcjToWgs[1].toString(), + gcjToWgs[0].toString() + ) + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + Constant.LOGIN_OUT -> { + Log.d(TAG, "退出登录") + //回到登录页 + SaveKeyValues.putValue("autoLogin", false) + mainActivity!!.startActivity(Intent(mainActivity, LoginActivity::class.java)) + mainActivity.finish() + } + } + } + } + + private fun updateMessageNumber() { + val list = BaseApplication.getDaoSession() + .noticeBeanDao + .queryBuilder() + .where(NoticeBeanDao.Properties.IsRead.eq("1")) + .list() + val size = list.size + if (size <= 0) { + messageNumView!!.visibility = View.GONE + } else { + messageNumView!!.visibility = View.VISIBLE + if (size > 9) { + messageNumView!!.text = "9+" + } else { + messageNumView!!.text = size.toString() + } + } + } + + override fun obtainUploadPositionResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainUploadPositionResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainRegisterResult(resultBean: ActionResultBean) { +// Log.d(TAG, "obtainRegisterResult: " + new Gson().toJson(resultBean)); + } + + override fun obtainMapConfig(resultBean: MapConfigBean) { + if (resultBean.isSuccess) { + StringHelper.saveMapConfigList(gson.toJson(resultBean.data.rows)) + } + } + + override fun obtainToiletListData(resultBean: ToiletListBean) { + if (resultBean.isSuccess) { + StringHelper.saveToiletList(gson.toJson(resultBean.data)) + } + } + + override fun onDestroy() { + super.onDestroy() + uploadPositionPresenter.disposeRetrofitRequest() + registerPresenter.disposeRetrofitRequest() + toiletListPresenter.disposeRetrofitRequest() + } + + companion object { + private const val TAG = "MainActivity" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveClientId]页面调用 + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]页面调用 + * 供[com.casic.dcms.service.UploadLocationService.onCreate]页面调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + + /** + * 供[MinePageFragment.obtainLoginOutResult]页面调用 + */ + fun sendEmptyMessage(what: Int) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendEmptyMessage(what) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java index beca2d1..fee32ff 100644 --- a/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java +++ b/app/src/main/java/com/casic/dcms/ui/PublicToiletActivity.java @@ -139,11 +139,11 @@ locationStreetView.setText("定位失败"); locationStreetView.setTextColor(Color.RED); } else { -// double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); -// Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); -// mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 -// //添加图片Marker -// addPictureMarker(point); + double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); + Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 1200);//标注到指定经纬度并放大地图显示 + //添加图片Marker + addPictureMarker(point); String address = aMapLocation.getAddress(); if (TextUtils.isEmpty(address)) { diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java deleted file mode 100644 index 16bd2e4..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.widget.TextView; - -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.casic.dcms.R; -import com.casic.dcms.adapter.HomeRecycleAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.HomePageBean; -import com.casic.dcms.bean.UserBean; -import com.casic.dcms.mvp.presenter.HomePagePresenterImpl; -import com.casic.dcms.mvp.presenter.UserDataPresenterImpl; -import com.casic.dcms.mvp.view.IHomePageView; -import com.casic.dcms.mvp.view.IUserDataView; -import com.casic.dcms.ui.BridgeMaintainActivity; -import com.casic.dcms.ui.CaseCheckActivity; -import com.casic.dcms.ui.CaseHandleActivity; -import com.casic.dcms.ui.CaseOnMapActivity; -import com.casic.dcms.ui.CaseSearchActivity; -import com.casic.dcms.ui.CaseUploadActivity; -import com.casic.dcms.ui.CaseUploadPackageActivity; -import com.casic.dcms.ui.CaseUploadQuicklyActivity; -import com.casic.dcms.ui.CaseVerifyActivity; -import com.casic.dcms.ui.ChangeShopInfoActivity; -import com.casic.dcms.ui.DataAnalysisActivity; -import com.casic.dcms.ui.DeptHandleActivity; -import com.casic.dcms.ui.OvertimeCaseActivity; -import com.casic.dcms.ui.PackageHandleActivity; -import com.casic.dcms.ui.PersonOnlineActivity; -import com.casic.dcms.ui.PipelineManagerActivity; -import com.casic.dcms.ui.PublicToiletActivity; -import com.casic.dcms.ui.StreetlightManagerActivity; -import com.casic.dcms.ui.UrgentCaseActivity; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.google.gson.Gson; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView; - -import butterknife.BindView; - -/** - * 此页面后期可能需要添加滑动吸顶效果 - */ -public class HomePageFragment extends BaseFragment implements IUserDataView, IHomePageView { - - @BindView(R.id.userIconView) - QMUIRadiusImageView userIconView; - @BindView(R.id.userNameView) - TextView userNameView; - @BindView(R.id.userDeptView) - TextView userDeptView; - - @BindView(R.id.homeRecyclerView) - RecyclerView homeRecyclerView; - - private Context context; - private UserDataPresenterImpl userDataPresenter; - private HomePagePresenterImpl homePagePresenter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_home; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - homePagePresenter = new HomePagePresenterImpl(this); - userDataPresenter = new UserDataPresenterImpl(this); - - //用户信息 - userDataPresenter.onReadyRetrofitRequest(); - //首页相关功能项 - homePagePresenter.onReadyRetrofitRequest("05"); - } - - @Override - protected void initEvent() { - //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 -// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); - Glide.with(this).load(R.mipmap.app_logo).into(userIconView); - } - - @SuppressLint("SetTextI18n") - @Override - public void obtainUserData(UserBean userBean) { - if (userBean.isSuccess()) { - UserBean.DataBean dataBean = userBean.getData(); - StringHelper.saveUserBean(new Gson().toJson(dataBean)); - - userNameView.setText(dataBean.getName()); - userDeptView.setText(dataBean.getDeptName() + dataBean.getRoleNames()); - } - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR); - } - - @Override - public void obtainHomePageResult(HomePageBean resultBean) { - if (resultBean.isSuccess()) { - HomeRecycleAdapter adapter = new HomeRecycleAdapter(context, resultBean.getData().getMenus()); - homeRecyclerView.setLayoutManager(new GridLayoutManager(context, 3)); - homeRecyclerView.setAdapter(adapter); - adapter.setOnGridItemClickListener(new HomeRecycleAdapter.OnGridItemClickListener() { - @Override - public void onClick(String itemName) { - Intent intent = new Intent(); - switch (itemName) { - case "案卷上报": - intent.setClass(context, CaseUploadActivity.class); - break; - case "快速上报": - intent.setClass(context, CaseUploadQuicklyActivity.class); - break; - case "三包上报": - intent.setClass(context, CaseUploadPackageActivity.class); - break; - case "案卷核实": - intent.setClass(context, CaseVerifyActivity.class); - break; - case "案卷核查": - intent.setClass(context, CaseCheckActivity.class); - break; - case "案卷处理": - intent.setClass(context, CaseHandleActivity.class); - break; - case "紧急要件": - intent.setClass(context, UrgentCaseActivity.class); - break; - case "超时督办": - intent.setClass(context, OvertimeCaseActivity.class); - break; - case "统计分析": - intent.setClass(context, DataAnalysisActivity.class); - break; - case "在岗人员": - intent.setClass(context, PersonOnlineActivity.class); - break; - case "案卷查询": - intent.setClass(context, CaseSearchActivity.class); - break; - case "案卷分布": - intent.setClass(context, CaseOnMapActivity.class); - break; - case "公厕保洁": - intent.setClass(context, PublicToiletActivity.class); - break; - case "三包处置": - intent.setClass(context, PackageHandleActivity.class); - break; - case "商铺变更": - intent.setClass(context, ChangeShopInfoActivity.class); - break; - case "部门处置": - intent.setClass(context, DeptHandleActivity.class); - break; - case "路桥养护": - intent.setClass(context, BridgeMaintainActivity.class); - break; - case "路灯管理": - intent.setClass(context, StreetlightManagerActivity.class); - break; - case "管网管理": - intent.setClass(context, PipelineManagerActivity.class); - break; - default: - break; - } - startActivity(intent); - } - }); - } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (userDataPresenter != null) { - userDataPresenter.disposeRetrofitRequest(); - } - if (homePagePresenter != null) { - homePagePresenter.disposeRetrofitRequest(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt new file mode 100644 index 0000000..75be68f --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/HomePageFragment.kt @@ -0,0 +1,106 @@ +package com.casic.dcms.ui.fragment + +import android.annotation.SuppressLint +import android.content.Intent +import androidx.recyclerview.widget.GridLayoutManager +import com.bumptech.glide.Glide +import com.casic.dcms.R +import com.casic.dcms.adapter.HomeRecycleAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.HomePageBean +import com.casic.dcms.bean.UserBean +import com.casic.dcms.mvp.presenter.HomePagePresenterImpl +import com.casic.dcms.mvp.presenter.UserDataPresenterImpl +import com.casic.dcms.mvp.view.IHomePageView +import com.casic.dcms.mvp.view.IUserDataView +import com.casic.dcms.ui.* +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.google.gson.Gson +import kotlinx.android.synthetic.main.fragment_home.* + +/** + * 此页面后期可能需要添加滑动吸顶效果 + */ +class HomePageFragment : BaseFragment(), IUserDataView, IHomePageView { + + private lateinit var userDataPresenter: UserDataPresenterImpl + private lateinit var homePagePresenter: HomePagePresenterImpl + + override fun initLayoutView(): Int = R.layout.fragment_home + + override fun setupTopBarLayout() { + + } + + override fun initData() { + homePagePresenter = HomePagePresenterImpl(this) + userDataPresenter = UserDataPresenterImpl(this) + + //用户信息 + userDataPresenter.onReadyRetrofitRequest() + //首页相关功能项 + homePagePresenter.onReadyRetrofitRequest("05") + } + + override fun initEvent() { + //QMUIRadiusImageView无法动态设置圆形头像,借助Glide实现圆形头像 +// Glide.with(this).load(R.mipmap.app_logo).apply(RequestOptions.circleCropTransform()).into(userIconView); + Glide.with(this).load(R.mipmap.app_logo).into(userIconView) + } + + @SuppressLint("SetTextI18n") + override fun obtainUserData(userBean: UserBean) { + if (userBean.isSuccess) { + val dataBean = userBean.data + StringHelper.saveUserBean(Gson().toJson(dataBean)) + // Log.d("TAG", new Gson().toJson(dataBean)); + userNameView.text = dataBean.name + userDeptView.text = dataBean.deptName + dataBean.roleNames + } + } + + override fun obtainDataFail() { + ToastHelper.showToast("获取用户信息失败,请重试", ToastHelper.ERROR) + } + + override fun obtainHomePageResult(resultBean: HomePageBean) { + if (resultBean.isSuccess) { + val adapter = HomeRecycleAdapter(context, resultBean.data.menus) + homeRecyclerView.layoutManager = GridLayoutManager(context, 3) + homeRecyclerView.adapter = adapter + adapter.setOnGridItemClickListener { itemName -> + val intent = Intent() + val context = requireContext() + when (itemName) { + "案卷上报" -> intent.setClass(context, CaseUploadActivity::class.java) + "快速上报" -> intent.setClass(context, CaseUploadQuicklyActivity::class.java) + "三包上报" -> intent.setClass(context, CaseUploadPackageActivity::class.java) + "案卷核实" -> intent.setClass(context, CaseVerifyActivity::class.java) + "案卷核查" -> intent.setClass(context, CaseCheckActivity::class.java) + "案卷处理" -> intent.setClass(context, CaseHandleActivity::class.java) + "紧急要件" -> intent.setClass(context, UrgentCaseActivity::class.java) + "超时督办" -> intent.setClass(context, OvertimeCaseActivity::class.java) + "统计分析" -> intent.setClass(context, DataAnalysisActivity::class.java) + "在岗人员" -> intent.setClass(context, PersonOnlineActivity::class.java) + "案卷查询" -> intent.setClass(context, CaseSearchActivity::class.java) + "案卷分布" -> intent.setClass(context, CaseOnMapActivity::class.java) + "公厕保洁" -> intent.setClass(context, PublicToiletActivity::class.java) + "三包处置" -> intent.setClass(context, PackageHandleActivity::class.java) + "商铺变更" -> intent.setClass(context, ChangeShopInfoActivity::class.java) + "部门处置" -> intent.setClass(context, DeptHandleActivity::class.java) + "路桥养护" -> intent.setClass(context, BridgeMaintainActivity::class.java) + "路灯管理" -> intent.setClass(context, StreetlightManagerActivity::class.java) + "管网管理" -> intent.setClass(context, PipelineManagerActivity::class.java) + } + startActivity(intent) + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + userDataPresenter.disposeRetrofitRequest() + homePagePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java index 4ffb02a..143b367 100644 --- a/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java +++ b/app/src/main/java/com/casic/dcms/ui/fragment/LightOnMapFragment.java @@ -23,7 +23,6 @@ import com.casic.dcms.bean.ActionResultBean; import com.casic.dcms.bean.LightMapBean; import com.casic.dcms.bean.StreetLightLocalBean; -import com.casic.dcms.greendao.DaoSession; import com.casic.dcms.greendao.StreetLightLocalBeanDao; import com.casic.dcms.mvp.presenter.LightControlPresenterImpl; import com.casic.dcms.mvp.presenter.LightMapPresenterImpl; @@ -76,7 +75,6 @@ private Context context; private LightMapPresenterImpl lightMapPresenter; - private DaoSession daoSession; private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = Constant.DELTA_LNG_75; @@ -92,8 +90,7 @@ @Override protected void setupTopBarLayout() { context = getContext(); - daoSession = BaseApplication.getStreetLightDaoSession(); - lightLocalBeanDao = daoSession.getStreetLightLocalBeanDao(); + lightLocalBeanDao = BaseApplication.getDaoSession().getStreetLightLocalBeanDao(); lightMapPresenter = new LightMapPresenterImpl(this); weakReferenceHandler = new WeakReferenceHandler(this); controlPresenter = new LightControlPresenterImpl(this); @@ -126,20 +123,21 @@ if (aMapLocation != null) { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReference.create(4326)); + mapView.setViewpointCenterAsync(point, 2800); List streetLightBeans = lightLocalBeanDao.loadAll(); List pointList = new ArrayList<>(); for (StreetLightLocalBean bean : streetLightBeans) { double longitude = bean.getLongitude(); double latitude = bean.getLatitude(); -// if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && -// Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { -// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); -// } - if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && - Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { + if (Math.abs(longitude - gcjToWgs[0]) <= Constant.DELTA_LNG_75 && + Math.abs(latitude - gcjToWgs[1]) <= Constant.DELTA_LAT_75) { pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); } +// if (Math.abs(longitude - Constant.DEFAULT_LNG) <= Constant.DELTA_LNG_75 && +// Math.abs(latitude - Constant.DEFAULT_LAT) <= Constant.DELTA_LAT_75) { +// pointList.add(new Point(longitude, latitude, SpatialReference.create(4326))); +// } } addPictureMarker(pointList); } @@ -469,12 +467,12 @@ bean.setLongitude(dataBean.getLongitude()); bean.setStatus(dataBean.getStatus()); - StreetLightLocalBean uniqueBean = daoSession.queryBuilder(StreetLightLocalBean.class) + StreetLightLocalBean uniqueBean = lightLocalBeanDao.queryBuilder() .where(StreetLightLocalBeanDao.Properties.LampId.eq(lampId)).unique(); if (uniqueBean == null) { - daoSession.insert(bean); + lightLocalBeanDao.insert(bean); } else { - daoSession.update(bean); + lightLocalBeanDao.update(bean); } } } diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java deleted file mode 100644 index c7e0b05..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.java +++ /dev/null @@ -1,270 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.app.ProgressDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.Switch; -import android.widget.TextView; - -import androidx.core.content.FileProvider; - -import com.casic.dcms.BuildConfig; -import com.casic.dcms.R; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.ActionResultBean; -import com.casic.dcms.bean.NewVersionBean; -import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl; -import com.casic.dcms.mvp.presenter.UpdatePresenterImpl; -import com.casic.dcms.mvp.view.ILoginOutView; -import com.casic.dcms.mvp.view.IUpdateVersionView; -import com.casic.dcms.ui.ChangePasswordActivity; -import com.casic.dcms.ui.HelpfulActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.ui.UserInfoActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.FileUtils; -import com.casic.dcms.utils.OtherUtils; -import com.casic.dcms.utils.SaveKeyValues; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.casic.dcms.utils.callback.IDownloadListener; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; - -import java.io.File; - -import butterknife.BindView; -import butterknife.OnClick; - -public class MinePageFragment extends BaseFragment implements View.OnClickListener, IUpdateVersionView, - ILoginOutView { - - private static final String TAG = "MinePageFragment"; - @BindView(R.id.deviceIdView) - TextView deviceIdView; - @BindView(R.id.versionCodeView) - TextView versionCodeView; - @BindView(R.id.autoLoginSwitch) - Switch autoLoginSwitch; - @BindView(R.id.backWorkSwitch) - Switch backWorkSwitch; - @BindView(R.id.loginOutButton) - QMUIRoundButton loginOutButton; - - private Context context; - private LoginOutPresenterImpl loginOutPresenter; - private UpdatePresenterImpl updatePresenter; - private ProgressDialog progressDialog; - private ClipboardManager clipboardManager; - - @Override - protected int initLayoutView() { - return R.layout.fragment_mine; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deviceIdView.setText(OtherUtils.obtainSimCardSerialNumber(context)); - versionCodeView.setText(BuildConfig.VERSION_NAME); - loginOutPresenter = new LoginOutPresenterImpl(this); - boolean isAutoLogin = (boolean) SaveKeyValues.getValue("autoLogin", false); - autoLoginSwitch.setChecked(isAutoLogin); - updatePresenter = new UpdatePresenterImpl(this); - clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - //下载进度条 - progressDialog = new ProgressDialog(context); - progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setProgressDrawable(context.getResources().getDrawable(R.drawable.bg_progress)); - progressDialog.setCanceledOnTouchOutside(false); - } - - @Override - protected void initEvent() { - loginOutButton.setChangeAlphaWhenPress(true); - autoLoginSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SaveKeyValues.putValue("autoLogin", isChecked); - } - }); - backWorkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("要允许应用运行在后台吗?") - .setMessage("允许[移动城管]运行在后台可能会缩短电池续航时间" + "\r\n您以后可以在手机[设置]中更改此设置") - .setCanceledOnTouchOutside(true) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //根据不同手机打开设置界面 - } - }) - .create().show(); - } else { - Log.d(TAG, "onCheckedChanged: 关闭低电量运行"); - } - } - }); - } - - @OnClick({R.id.userNameLayout, R.id.passwordLayout, R.id.helpfulLayout, R.id.copyView, R.id.updateVersionView, R.id.loginOutButton}) - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.userNameLayout: - startActivity(new Intent(context, UserInfoActivity.class)); - break; - case R.id.passwordLayout: - startActivity(new Intent(context, ChangePasswordActivity.class)); - break; - case R.id.helpfulLayout: - startActivity(new Intent(context, HelpfulActivity.class)); - break; - case R.id.copyView: - ClipData clipData = ClipData.newPlainText("deviceId", deviceIdView.getText().toString()); - clipboardManager.setPrimaryClip(clipData); - ToastHelper.showToast("复制成功", ToastHelper.SUCCESS); - break; - case R.id.updateVersionView: - updatePresenter.onReadyRetrofitRequest(); - break; - case R.id.loginOutButton: - //退出登录对话框 - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("退出登录") - .setMessage("确定要退出吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - loginOutPresenter.onReadyRetrofitRequest(); - } - }).create().show(); - break; - default: - break; - } - } - - @Override - public void obtainLoginOutResult(ActionResultBean resultBean) { - MainActivity.sendEmptyMessage(Constant.LOGIN_OUT); - } - - @Override - public void showProgress() { - OtherUtils.showLoadingDialog(context, "请求中,请稍后"); - } - - @Override - public void hideProgress() { - OtherUtils.dismissLoadingDialog(); - } - - @Override - public void obtainVersionResult(NewVersionBean resultBean) { -// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - NewVersionBean.DataBean data = resultBean.getData(); - String version = data.getVersion(); - if (BuildConfig.VERSION_NAME.equals(version)) { - ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO); - } else { - String downloadUrl = StringHelper.appendDownloadUrl(data.getDownloadUrl()); - //http://111.198.10.15:11409/static/app/v1.1.0.0.apk - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("版本更新") - .setMessage("确定下载新版本吗?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - //下载新版本 - progressDialog.setMessage("下载新版本中..."); - progressDialog.show(); - if (progressDialog.getProgress() != 0) { - progressDialog.setProgress(0);//防止下载到中途却卡住无法再进行下载 - return; - } - downloadApk(downloadUrl); - } - }).create().show(); - } - } - } - - //下载apk - private void downloadApk(String url) { - FileUtils.downloadFile(url, new IDownloadListener() { - @Override - public void onDownloadStart(long totalBytes) { - progressDialog.setMax((int) totalBytes); - } - - @Override - public void onProgressChanged(long currentBytes) { - progressDialog.setProgress((int) currentBytes); - } - - @Override - public void onDownloadEnd(File file) { - progressDialog.setProgress(0);//防止下载完成却卡住的情况 - progressDialog.dismiss(); - installApk(file); - } - }); - } - - //安装apk文件 - private void installApk(File apk) { - Intent intent = new Intent(Intent.ACTION_VIEW); - Uri data; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//判断版本大于等于7.0 - // 通过FileProvider创建一个content类型的Uri - data = FileProvider.getUriForFile(context, "com.casic.dcms.install.fileProvider", apk); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);// 给目标应用一个临时授权 - } else { - data = Uri.fromFile(apk); - } - intent.setDataAndType(data, "application/vnd.android.package-archive"); - context.startActivity(intent); - } - - @Override - public void obtainDataFail() { - ToastHelper.showToast("操作失败", ToastHelper.ERROR); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (loginOutPresenter != null) { - loginOutPresenter.disposeRetrofitRequest(); - } - if (updatePresenter != null) { - updatePresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt new file mode 100644 index 0000000..a33bb4e --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/MinePageFragment.kt @@ -0,0 +1,183 @@ +package com.casic.dcms.ui.fragment + +import android.app.ProgressDialog +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import androidx.core.content.FileProvider +import com.casic.dcms.BuildConfig +import com.casic.dcms.R +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.ActionResultBean +import com.casic.dcms.bean.NewVersionBean +import com.casic.dcms.mvp.presenter.LoginOutPresenterImpl +import com.casic.dcms.mvp.presenter.UpdatePresenterImpl +import com.casic.dcms.mvp.view.ILoginOutView +import com.casic.dcms.mvp.view.IUpdateVersionView +import com.casic.dcms.ui.ChangePasswordActivity +import com.casic.dcms.ui.HelpfulActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.ui.UserInfoActivity +import com.casic.dcms.utils.* +import com.casic.dcms.utils.callback.IDownloadListener +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction +import kotlinx.android.synthetic.main.fragment_mine.* +import java.io.File + +class MinePageFragment : BaseFragment(), IUpdateVersionView, ILoginOutView { + + private var clipboardManager: ClipboardManager? = null + private lateinit var loginOutPresenter: LoginOutPresenterImpl + private lateinit var updatePresenter: UpdatePresenterImpl + private lateinit var progressDialog: ProgressDialog + + override fun initLayoutView(): Int = R.layout.fragment_mine + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deviceIdView!!.text = OtherUtils.obtainSimCardSerialNumber(context) + versionCodeView!!.text = BuildConfig.VERSION_NAME + loginOutPresenter = LoginOutPresenterImpl(this) + val isAutoLogin = SaveKeyValues.getValue("autoLogin", false) as Boolean + autoLoginSwitch!!.isChecked = isAutoLogin + updatePresenter = UpdatePresenterImpl(this) + clipboardManager = context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + + //下载进度条 + progressDialog = ProgressDialog(context) + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + progressDialog.setProgressDrawable(context?.resources!!.getDrawable(R.drawable.bg_progress)) + progressDialog.setCanceledOnTouchOutside(false) + } + + override fun initEvent() { + userNameLayout.setOnClickListener { + startActivity(Intent(context, UserInfoActivity::class.java)) + } + passwordLayout.setOnClickListener { + startActivity(Intent(context, ChangePasswordActivity::class.java)) + } + helpfulLayout.setOnClickListener { + startActivity(Intent(context, HelpfulActivity::class.java)) + } + autoLoginSwitch!!.setOnCheckedChangeListener { buttonView, isChecked -> + SaveKeyValues.putValue("autoLogin", isChecked) + } + copyView.setOnClickListener { + val clipData = ClipData.newPlainText("deviceId", deviceIdView!!.text.toString()) + clipboardManager!!.setPrimaryClip(clipData) + ToastHelper.showToast("复制成功", ToastHelper.SUCCESS) + } + updateVersionView.setOnClickListener { updatePresenter.onReadyRetrofitRequest() } + + loginOutButton!!.setChangeAlphaWhenPress(true) + loginOutButton.setOnClickListener { + MessageDialogBuilder(context) + .setTitle("退出登录") + .setMessage("确定要退出吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + loginOutPresenter.onReadyRetrofitRequest() + }.create().show() + } + } + + override fun obtainLoginOutResult(resultBean: ActionResultBean) { + MainActivity.sendEmptyMessage(Constant.LOGIN_OUT) + } + + override fun showProgress() { + OtherUtils.showLoadingDialog(context, "请求中,请稍后") + } + + override fun hideProgress() { + OtherUtils.dismissLoadingDialog() + } + + override fun obtainVersionResult(resultBean: NewVersionBean) { +// Log.d(TAG, "obtainVersionResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val data = resultBean.data + val version = data.version + if (BuildConfig.VERSION_NAME == version) { + ToastHelper.showToast("暂无新版本,无需更新", ToastHelper.INFO) + } else { + val downloadUrl = StringHelper.appendDownloadUrl(data.downloadUrl) + //http://111.198.10.15:11409/static/app/v1.1.0.0.apk + MessageDialogBuilder(context) + .setTitle("版本更新") + .setMessage("确定下载新版本吗?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定", QMUIDialogAction.ActionListener { dialog, index -> + dialog.dismiss() + //下载新版本 + progressDialog.setMessage("下载新版本中...") + progressDialog.show() + if (progressDialog.progress != 0) { + progressDialog.progress = 0 //防止下载到中途却卡住无法再进行下载 + return@ActionListener + } + downloadApk(downloadUrl) + }).create().show() + } + } + } + + //下载apk + private fun downloadApk(url: String) { + FileUtils.downloadFile(url, object : IDownloadListener { + override fun onDownloadStart(totalBytes: Long) { + progressDialog.max = totalBytes.toInt() + } + + override fun onProgressChanged(currentBytes: Long) { + progressDialog.progress = currentBytes.toInt() + } + + override fun onDownloadEnd(file: File) { + progressDialog.progress = 0 //防止下载完成却卡住的情况 + progressDialog.dismiss() + installApk(file) + } + }) + } + + //安装apk文件 + private fun installApk(apk: File) { + val intent = Intent(Intent.ACTION_VIEW) + val data: Uri + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //判断版本大于等于7.0 + // 通过FileProvider创建一个content类型的Uri + data = FileProvider.getUriForFile( + requireContext(), + "com.casic.dcms.install.fileProvider", apk + ) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 给目标应用一个临时授权 + } else { + data = Uri.fromFile(apk) + } + intent.setDataAndType(data, "application/vnd.android.package-archive") + requireContext().startActivity(intent) + } + + override fun obtainDataFail() { + ToastHelper.showToast("操作失败", ToastHelper.ERROR) + } + + override fun onDestroyView() { + super.onDestroyView() + loginOutPresenter.disposeRetrofitRequest() + updatePresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java deleted file mode 100644 index e2488fc..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -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.greendao.NoticeBeanDao; -import com.casic.dcms.ui.CaseDetailActivity; -import com.casic.dcms.ui.MainActivity; -import com.casic.dcms.utils.Constant; -import com.casic.dcms.utils.StringHelper; -import com.igexin.sdk.message.GTTransmitMessage; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; - -import org.jetbrains.annotations.NotNull; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class NoticePageFragment extends BaseFragment { - - private static final String TAG = "NoticePageFragment"; - @BindView(R.id.swipeRecyclerView) - RecyclerView swipeRecyclerView; - - private Context context; - private List noticeBeans = new ArrayList<>(); - private SwipeViewAdapter swipeViewAdapter; - private DaoSession daoSession; - private static WeakReferenceHandler weakReferenceHandler; - - @Override - protected int initLayoutView() { - return R.layout.fragment_notice; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - daoSession = BaseApplication.getDaoSession(); - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeans = daoSession.queryBuilder(NoticeBean.class) - .where(NoticeBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeBeanDao.Properties.PushDate)//按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - - weakReferenceHandler = new WeakReferenceHandler(this); - } - - @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - int position = viewHolder.getAdapterPosition(); - daoSession.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - 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); - } - }); - swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - //更新小红点 - MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - daoSession.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); - } - - /** - * 供{@link com.casic.dcms.service.GeTuiIntentService#onReceiveMessageData(Context, GTTransmitMessage)}调用 - */ - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - private static class WeakReferenceHandler extends Handler { - private WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - - @Override - public void handleMessage(@NotNull Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == Constant.PUSH_MESSAGE_DATA) { - NoticeBean noticeBean = (NoticeBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean);//新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt new file mode 100644 index 0000000..05e6ddb --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/NoticePageFragment.kt @@ -0,0 +1,152 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.os.Handler +import android.os.Message +import android.text.TextUtils +import android.util.Log +import android.view.ViewGroup +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +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.NoticeBeanDao +import com.casic.dcms.ui.CaseDetailActivity +import com.casic.dcms.ui.MainActivity +import com.casic.dcms.utils.Constant +import com.casic.dcms.utils.StringHelper +import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction +import com.qmuiteam.qmui.recyclerView.QMUISwipeAction +import kotlinx.android.synthetic.main.fragment_notice.* +import java.lang.ref.WeakReference +import java.util.* + +class NoticePageFragment : BaseFragment() { + + private lateinit var noticeBeanDao: NoticeBeanDao + private lateinit var swipeViewAdapter: SwipeViewAdapter + private var noticeBeans: MutableList = ArrayList() + + override fun initLayoutView(): Int = R.layout.fragment_notice + + override fun setupTopBarLayout() { + + } + + override fun initData() { + swipeViewAdapter = SwipeViewAdapter(context) + //根据loginName加载历史数据 + val account = StringHelper.getUserAccount() + if (TextUtils.isEmpty(account)) { + return + } + noticeBeanDao = BaseApplication.getDaoSession().noticeBeanDao + noticeBeans = noticeBeanDao.queryBuilder() + .where(NoticeBeanDao.Properties.UserAccount.eq(account)) + .orderDesc(NoticeBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 + .list() + swipeViewAdapter.setData(noticeBeans) + weakReferenceHandler = WeakReferenceHandler(this) + } + + override fun initEvent() { + val swipeAction = QMUIRVItemSwipeAction(true, object : QMUIRVItemSwipeAction.Callback() { + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = viewHolder.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + + override fun getSwipeDirection( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ): Int { + return QMUIRVItemSwipeAction.SWIPE_LEFT + } + + override fun onClickAction( + swipeAction: QMUIRVItemSwipeAction, + selected: RecyclerView.ViewHolder, + action: QMUISwipeAction + ) { + super.onClickAction(swipeAction, selected, action) + //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + val position = selected.adapterPosition + noticeBeanDao.delete(noticeBeans[position]) + swipeViewAdapter.remove(position) + } + }) + swipeAction.attachToRecyclerView(swipeRecyclerView) + swipeRecyclerView!!.layoutManager = object : LinearLayoutManager(context) { + override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams { + return RecyclerView.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + } + swipeRecyclerView!!.addItemDecoration( + DividerItemDecoration( + context, + DividerItemDecoration.VERTICAL + ) + ) + swipeRecyclerView!!.adapter = swipeViewAdapter + swipeViewAdapter.setOnItemClickListener { position -> //更新小红点 + MainActivity.sendEmptyMessage(Constant.MESSAGE_NUMBER) + + //点击之后之后,未读消息变为已读消息 + val noticeBean = noticeBeans[position] + noticeBean.isRead = "0" + noticeBeanDao.update(noticeBean) + swipeViewAdapter.notifyDataSetChanged() + val caseId = noticeBeans[position].caseId + val intent = Intent(context, CaseDetailActivity::class.java) + intent.putExtra("id", caseId) + startActivity(intent) + } + } + + private class WeakReferenceHandler(fragment: NoticePageFragment) : Handler() { + private val reference: WeakReference = WeakReference(fragment) + override fun handleMessage(msg: Message) { + val noticePageFragment: NoticePageFragment? + try { + noticePageFragment = reference.get() + val noticeBeans = noticePageFragment!!.noticeBeans + if (msg.what == Constant.PUSH_MESSAGE_DATA) { + val noticeBean = msg.obj as NoticeBean + Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.caseId) + noticeBeans.add(0, noticeBean) //新消息永远放到第一个 + //更新数据 + noticePageFragment.swipeViewAdapter.setData(noticeBeans) + } + } catch (e: NullPointerException) { + e.printStackTrace() + } + } + + } + + companion object { + private const val TAG = "NoticePageFragment" + private var weakReferenceHandler: WeakReferenceHandler? = null + + /** + * 供[com.casic.dcms.service.GeTuiIntentService.onReceiveMessageData]调用 + */ + fun sendMessage(msg: Message?) { + if (weakReferenceHandler == null) { + return + } + weakReferenceHandler!!.sendMessage(msg!!) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java deleted file mode 100644 index 13aa09b..0000000 --- a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.casic.dcms.ui.fragment; - -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.text.TextUtils; -import android.view.View; -import android.widget.ExpandableListView; - -import com.casic.dcms.R; -import com.casic.dcms.adapter.DeptExpandableAdapter; -import com.casic.dcms.base.BaseFragment; -import com.casic.dcms.bean.DeptTreeBean; -import com.casic.dcms.bean.PersonBean; -import com.casic.dcms.bean.PhoneBookBean; -import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl; -import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl; -import com.casic.dcms.mvp.view.IDeptTreeView; -import com.casic.dcms.mvp.view.IPhoneBookView; -import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.ToastHelper; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; - -import java.util.ArrayList; -import java.util.List; - -import butterknife.BindView; - -public class PhonePageFragment extends BaseFragment implements IDeptTreeView, IPhoneBookView { - - private static final String TAG = "PhonePageFragment"; - - @BindView(R.id.deptTreeView) - ExpandableListView deptTreeView; - - private Context context; - private DeptTreePresenterImpl deptTreePresenter; - private PhoneBookPresenterImpl phoneBookPresenter; - private List deptList = new ArrayList<>();//部门名集合 - private List> deptAndPersons = new ArrayList<>();//个人信息集合的集合 - private DeptExpandableAdapter expandableAdapter; - - @Override - protected int initLayoutView() { - return R.layout.fragment_phone; - } - - @Override - protected void setupTopBarLayout() { - context = getContext(); - } - - @Override - protected void initData() { - deptTreePresenter = new DeptTreePresenterImpl(this); - deptTreePresenter.onReadyRetrofitRequest("0"); - phoneBookPresenter = new PhoneBookPresenterImpl(this); - expandableAdapter = new DeptExpandableAdapter(context); - } - - @Override - protected void initEvent() { - - } - - - @Override - public void obtainDeptTreeResult(DeptTreeBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - //先获取部门树,在往树结构里面加人 - if (resultBean.isSuccess()) { - List listBeans = resultBean.getData().getList(); - deptList.clear(); - for (DeptTreeBean.DataBean.ListBean bean : listBeans) { - deptList.add(bean.getName()); - } - if (deptList.size() > 0) { - phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().getDeptId()); - } - } - } - - @Override - public void obtainPhoneBookResult(PhoneBookBean resultBean) { -// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); - if (resultBean.isSuccess()) { - List dataBeans = resultBean.getData(); - deptAndPersons.clear(); - for (String title : deptList) { - List beanList = new ArrayList<>(); - for (PhoneBookBean.DataBean dataBean : dataBeans) { - if (title.equals(dataBean.getDeptName())) { - PersonBean personBean = new PersonBean(); - personBean.setPersonDept(dataBean.getDeptName()); - personBean.setPersonName(dataBean.getName()); - personBean.setPersonPhone(dataBean.getPhone()); - - beanList.add(personBean); - } - } - deptAndPersons.add(beanList); - } - //展示部门树以及人员 - expandableAdapter.setData(deptList, deptAndPersons); - deptTreeView.setAdapter(expandableAdapter); - //默认展开数据 - for (int i = 0; i < expandableAdapter.getGroupCount(); i++) { - deptTreeView.expandGroup(i); - } - deptTreeView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { - @Override - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - PersonBean personBean = deptAndPersons.get(groupPosition).get(childPosition); - callPhone(personBean.getPersonName(), personBean.getPersonPhone()); - return true; - } - }); - } - } - - /** - * 直接呼叫电话 - */ - private void callPhone(String personName, String personPhone) { - if (TextUtils.isEmpty(personPhone)) { - ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR); - return; - } - new QMUIDialog.MessageDialogBuilder(context) - .setTitle("提示") - .setMessage("是否确定拨打[" + personName + "]的电话?") - .setCanceledOnTouchOutside(false) - .addAction("取消", (dialog, index) -> dialog.dismiss()) - .addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - dialog.dismiss(); - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_CALL); - intent.setData(Uri.parse("tel:" + personPhone)); - startActivity(intent); - } - }) - .create().show(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - if (deptTreePresenter != null) { - deptTreePresenter.disposeRetrofitRequest(); - } - if (phoneBookPresenter != null) { - phoneBookPresenter.disposeRetrofitRequest(); - } - } -} diff --git a/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt new file mode 100644 index 0000000..e606857 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/ui/fragment/PhonePageFragment.kt @@ -0,0 +1,124 @@ +package com.casic.dcms.ui.fragment + +import android.content.Intent +import android.net.Uri +import android.text.TextUtils +import com.casic.dcms.R +import com.casic.dcms.adapter.DeptExpandableAdapter +import com.casic.dcms.base.BaseFragment +import com.casic.dcms.bean.DeptTreeBean +import com.casic.dcms.bean.PersonBean +import com.casic.dcms.bean.PhoneBookBean +import com.casic.dcms.mvp.presenter.DeptTreePresenterImpl +import com.casic.dcms.mvp.presenter.PhoneBookPresenterImpl +import com.casic.dcms.mvp.view.IDeptTreeView +import com.casic.dcms.mvp.view.IPhoneBookView +import com.casic.dcms.utils.StringHelper +import com.casic.dcms.utils.ToastHelper +import com.qmuiteam.qmui.widget.dialog.QMUIDialog +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MessageDialogBuilder +import kotlinx.android.synthetic.main.fragment_phone.* +import java.util.* + +class PhonePageFragment : BaseFragment(), IDeptTreeView, IPhoneBookView { + + private lateinit var deptTreePresenter: DeptTreePresenterImpl + private lateinit var phoneBookPresenter: PhoneBookPresenterImpl + private lateinit var expandableAdapter: DeptExpandableAdapter + private val deptList: MutableList = ArrayList() //部门名集合 + private val deptAndPersons: MutableList> = ArrayList() //个人信息集合的集合 + + override fun initLayoutView(): Int { + return R.layout.fragment_phone + } + + override fun setupTopBarLayout() { + + } + + override fun initData() { + deptTreePresenter = DeptTreePresenterImpl(this) + deptTreePresenter.onReadyRetrofitRequest("0") + phoneBookPresenter = PhoneBookPresenterImpl(this) + expandableAdapter = DeptExpandableAdapter(context) + } + + override fun initEvent() {} + + override fun obtainDeptTreeResult(resultBean: DeptTreeBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + //先获取部门树,在往树结构里面加人 + if (resultBean.isSuccess) { + val listBeans = resultBean.data.list + deptList.clear() + for (bean in listBeans) { + deptList.add(bean.name) + } + if (deptList.size > 0) { + phoneBookPresenter.onReadyRetrofitRequest(StringHelper.getUserBean().deptId) + } + } + } + + override fun obtainPhoneBookResult(resultBean: PhoneBookBean) { +// Log.d(TAG, "obtainPhoneBookResult: " + new Gson().toJson(resultBean)); + if (resultBean.isSuccess) { + val dataBeans = resultBean.data + deptAndPersons.clear() + for (title in deptList) { + val beanList: MutableList = ArrayList() + for (dataBean in dataBeans) { + if (title == dataBean.deptName) { + val personBean = PersonBean() + personBean.personDept = dataBean.deptName + personBean.personName = dataBean.name + personBean.personPhone = dataBean.phone + beanList.add(personBean) + } + } + deptAndPersons.add(beanList) + } + //展示部门树以及人员 + expandableAdapter.setData(deptList, deptAndPersons) + deptTreeView.setAdapter(expandableAdapter) + //默认展开数据 + for (i in 0 until expandableAdapter.groupCount) { + deptTreeView.expandGroup(i) + } + deptTreeView.setOnChildClickListener { parent, v, groupPosition, childPosition, id -> + val personBean = deptAndPersons[groupPosition][childPosition] + callPhone(personBean.personName, personBean.personPhone) + true + } + } + } + + /** + * 直接呼叫电话 + */ + private fun callPhone(personName: String, personPhone: String) { + if (TextUtils.isEmpty(personPhone)) { + ToastHelper.showToast("手机号为空,无法拨号", ToastHelper.ERROR) + return + } + MessageDialogBuilder(context) + .setTitle("提示") + .setMessage("是否确定拨打[$personName]的电话?") + .setCanceledOnTouchOutside(false) + .addAction("取消") { dialog: QMUIDialog, index: Int -> dialog.dismiss() } + .addAction("确定") { dialog, index -> + dialog.dismiss() + val intent = Intent() + intent.action = Intent.ACTION_CALL + intent.data = Uri.parse("tel:$personPhone") + startActivity(intent) + } + .create().show() + } + + override fun onDestroyView() { + super.onDestroyView() + deptTreePresenter.disposeRetrofitRequest() + phoneBookPresenter.disposeRetrofitRequest() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/Constant.java b/app/src/main/java/com/casic/dcms/utils/Constant.java index 9bc9aa1..e41c903 100644 --- a/app/src/main/java/com/casic/dcms/utils/Constant.java +++ b/app/src/main/java/com/casic/dcms/utils/Constant.java @@ -81,6 +81,31 @@ public static final double DELTA_LNG_75 = 0.00075; public static final double DELTA_LAT_75 = 0.00075; + /** + * 西路社区:116.0497949886485,27.7523090448274 + * 永胜、中山社区:116.04801256908105,27.764489266672403 + * 城北社区:116.05083134025335,27.78274489130171 + * 一木社区:116.06179579161108,27.780238298884917 + * 新街社区:116.0569392645266,27.775902775818285 + * 南道社区:116.05398381594571,27.765387699087427 + * 胜利社区:116.05763011146338,27.758979599138858 + * 黄家社区:116.06998477480374,27.766637205647783 + * 中大社区:116.06510639190675,27.752823008396483 + * 中大、子正社区:116.08546817209574,27.758020310248185 + * 子正、高新区:116.11514568328859,27.774506608946538 + */ + public static final double[] XILU = {116.0497949886485, 27.7523090448274}; + public static final double[] YONG_ZHONG = {116.04801256908105, 27.764489266672403}; + public static final double[] CHENGBEI = {116.05083134025335, 27.78274489130171}; + public static final double[] YIMU = {116.06179579161108, 27.780238298884917}; + public static final double[] XINJIE = {116.0569392645266, 27.775902775818285}; + public static final double[] NANDAO = {116.05398381594571, 27.765387699087427}; + public static final double[] SHENGLI = {116.05763011146338, 27.758979599138858}; + public static final double[] HUANGJIA = {116.06998477480374, 27.766637205647783}; + public static final double[] ZHONGDA = {116.06510639190675, 27.752823008396483}; + public static final double[] ZHONG_ZI = {116.08546817209574, 27.758020310248185}; + public static final double[] ZI_GAO = {116.11514568328859, 27.774506608946538}; + //单独网络请求接口名 public static final String SHOP_DETAIL = "/shop/merchant/detail?merchantId="; public static final String SHOP_PUNISH_LIST = "/shop/punish/listByMerchant?merchantId="; diff --git a/app/src/main/java/com/casic/dcms/utils/StringHelper.java b/app/src/main/java/com/casic/dcms/utils/StringHelper.java index a7cb679..df96c00 100644 --- a/app/src/main/java/com/casic/dcms/utils/StringHelper.java +++ b/app/src/main/java/com/casic/dcms/utils/StringHelper.java @@ -1,5 +1,6 @@ package com.casic.dcms.utils; +import android.content.res.AssetManager; import android.text.TextUtils; import android.util.Log; @@ -11,6 +12,9 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -206,6 +210,30 @@ } /** + * 获取本地Asserts文件内容 + */ + public static String getAssetsData(AssetManager manager, String fileName) { + try { + InputStreamReader inputStreamReader = new InputStreamReader(manager.open(fileName)); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + StringBuilder data = new StringBuilder(); + String s; + try { + while ((s = bufferedReader.readLine()) != null) { + data.append(s); + } + Log.d(TAG, "getAssetsData: " + data); + return data.toString(); + } catch (IOException e) { + e.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** * 三包处罚转换 */ public static String StringToType(String s) { diff --git a/app/src/main/res/layout/fragment_mine.xml b/app/src/main/res/layout/fragment_mine.xml index 7f4dafc..ee739c4 100644 --- a/app/src/main/res/layout/fragment_mine.xml +++ b/app/src/main/res/layout/fragment_mine.xml @@ -99,30 +99,6 @@ - - - - - - - - -