diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push_small.png b/app/src/main/res/drawable-xxhdpi/push_small.png new file mode 100644 index 0000000..dd40d82 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push_small.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push_small.png b/app/src/main/res/drawable-xxhdpi/push_small.png new file mode 100644 index 0000000..dd40d82 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push.png b/app/src/main/res/drawable-xxxhdpi/push.png new file mode 100644 index 0000000..9b01303 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push_small.png b/app/src/main/res/drawable-xxhdpi/push_small.png new file mode 100644 index 0000000..dd40d82 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push.png b/app/src/main/res/drawable-xxxhdpi/push.png new file mode 100644 index 0000000..9b01303 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push_small.png b/app/src/main/res/drawable-xxxhdpi/push_small.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push_small.png Binary files differ diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push_small.png b/app/src/main/res/drawable-xxhdpi/push_small.png new file mode 100644 index 0000000..dd40d82 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push.png b/app/src/main/res/drawable-xxxhdpi/push.png new file mode 100644 index 0000000..9b01303 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push_small.png b/app/src/main/res/drawable-xxxhdpi/push_small.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable/dash_line_gray.xml b/app/src/main/res/drawable/dash_line_gray.xml new file mode 100644 index 0000000..61ca4c0 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_gray.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push_small.png b/app/src/main/res/drawable-xxhdpi/push_small.png new file mode 100644 index 0000000..dd40d82 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push.png b/app/src/main/res/drawable-xxxhdpi/push.png new file mode 100644 index 0000000..9b01303 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push_small.png b/app/src/main/res/drawable-xxxhdpi/push_small.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable/dash_line_gray.xml b/app/src/main/res/drawable/dash_line_gray.xml new file mode 100644 index 0000000..61ca4c0 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_gray.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dot_red.xml b/app/src/main/res/drawable/dot_red.xml new file mode 100644 index 0000000..fa97466 --- /dev/null +++ b/app/src/main/res/drawable/dot_red.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push_small.png b/app/src/main/res/drawable-xxhdpi/push_small.png new file mode 100644 index 0000000..dd40d82 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push.png b/app/src/main/res/drawable-xxxhdpi/push.png new file mode 100644 index 0000000..9b01303 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push_small.png b/app/src/main/res/drawable-xxxhdpi/push_small.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable/dash_line_gray.xml b/app/src/main/res/drawable/dash_line_gray.xml new file mode 100644 index 0000000..61ca4c0 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_gray.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dot_red.xml b/app/src/main/res/drawable/dot_red.xml new file mode 100644 index 0000000..fa97466 --- /dev/null +++ b/app/src/main/res/drawable/dot_red.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_alarm_tag.xml b/app/src/main/res/drawable/ic_alarm_tag.xml new file mode 100644 index 0000000..8650128 --- /dev/null +++ b/app/src/main/res/drawable/ic_alarm_tag.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push_small.png b/app/src/main/res/drawable-xxhdpi/push_small.png new file mode 100644 index 0000000..dd40d82 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push.png b/app/src/main/res/drawable-xxxhdpi/push.png new file mode 100644 index 0000000..9b01303 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push_small.png b/app/src/main/res/drawable-xxxhdpi/push_small.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable/dash_line_gray.xml b/app/src/main/res/drawable/dash_line_gray.xml new file mode 100644 index 0000000..61ca4c0 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_gray.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dot_red.xml b/app/src/main/res/drawable/dot_red.xml new file mode 100644 index 0000000..fa97466 --- /dev/null +++ b/app/src/main/res/drawable/dot_red.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_alarm_tag.xml b/app/src/main/res/drawable/ic_alarm_tag.xml new file mode 100644 index 0000000..8650128 --- /dev/null +++ b/app/src/main/res/drawable/ic_alarm_tag.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/src/main/res/layout/fragment_mine.xml b/app/src/main/res/layout/fragment_mine.xml index 8ede317..e672c7e 100644 --- a/app/src/main/res/layout/fragment_mine.xml +++ b/app/src/main/res/layout/fragment_mine.xml @@ -89,6 +89,23 @@ android:textColorLink="@color/mainThemeColor" android:textSize="@dimen/sp_16" /> + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push_small.png b/app/src/main/res/drawable-xxhdpi/push_small.png new file mode 100644 index 0000000..dd40d82 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push.png b/app/src/main/res/drawable-xxxhdpi/push.png new file mode 100644 index 0000000..9b01303 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push_small.png b/app/src/main/res/drawable-xxxhdpi/push_small.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable/dash_line_gray.xml b/app/src/main/res/drawable/dash_line_gray.xml new file mode 100644 index 0000000..61ca4c0 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_gray.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dot_red.xml b/app/src/main/res/drawable/dot_red.xml new file mode 100644 index 0000000..fa97466 --- /dev/null +++ b/app/src/main/res/drawable/dot_red.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_alarm_tag.xml b/app/src/main/res/drawable/ic_alarm_tag.xml new file mode 100644 index 0000000..8650128 --- /dev/null +++ b/app/src/main/res/drawable/ic_alarm_tag.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/src/main/res/layout/fragment_mine.xml b/app/src/main/res/layout/fragment_mine.xml index 8ede317..e672c7e 100644 --- a/app/src/main/res/layout/fragment_mine.xml +++ b/app/src/main/res/layout/fragment_mine.xml @@ -89,6 +89,23 @@ android:textColorLink="@color/mainThemeColor" android:textSize="@dimen/sp_16" /> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_notice.xml b/app/src/main/res/layout/fragment_notice.xml index 7015d7b..aece8b8 100644 --- a/app/src/main/res/layout/fragment_notice.xml +++ b/app/src/main/res/layout/fragment_notice.xml @@ -7,4 +7,37 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push_small.png b/app/src/main/res/drawable-xxhdpi/push_small.png new file mode 100644 index 0000000..dd40d82 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push.png b/app/src/main/res/drawable-xxxhdpi/push.png new file mode 100644 index 0000000..9b01303 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push_small.png b/app/src/main/res/drawable-xxxhdpi/push_small.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable/dash_line_gray.xml b/app/src/main/res/drawable/dash_line_gray.xml new file mode 100644 index 0000000..61ca4c0 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_gray.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dot_red.xml b/app/src/main/res/drawable/dot_red.xml new file mode 100644 index 0000000..fa97466 --- /dev/null +++ b/app/src/main/res/drawable/dot_red.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_alarm_tag.xml b/app/src/main/res/drawable/ic_alarm_tag.xml new file mode 100644 index 0000000..8650128 --- /dev/null +++ b/app/src/main/res/drawable/ic_alarm_tag.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/src/main/res/layout/fragment_mine.xml b/app/src/main/res/layout/fragment_mine.xml index 8ede317..e672c7e 100644 --- a/app/src/main/res/layout/fragment_mine.xml +++ b/app/src/main/res/layout/fragment_mine.xml @@ -89,6 +89,23 @@ android:textColorLink="@color/mainThemeColor" android:textSize="@dimen/sp_16" /> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_notice.xml b/app/src/main/res/layout/fragment_notice.xml index 7015d7b..aece8b8 100644 --- a/app/src/main/res/layout/fragment_notice.xml +++ b/app/src/main/res/layout/fragment_notice.xml @@ -7,4 +7,37 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_notice_rv.xml b/app/src/main/res/layout/item_notice_rv.xml new file mode 100644 index 0000000..c54568c --- /dev/null +++ b/app/src/main/res/layout/item_notice_rv.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d22e9ec..b47f9a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'org.greenrobot.greendao' android { signingConfigs { @@ -35,6 +36,10 @@ * 缺点:只能运行在arm64-v8上,要放弃部分老旧设备用户 * */ ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8" } + + manifestPlaceholders = [ + GETUI_APPID: "HKv8K9qARd6WckZ1o2Vbu4" + ] } buildTypes { @@ -61,6 +66,12 @@ outputFileName = defaultConfig.versionName + ".apk" } } + + greendao { + schemaVersion 1//数据库版本号 + targetGenDir 'src/main/java'//设置DaoMaster、DaoSession、Dao目录 + daoPackage 'com.casic.app.smartwell.greendao'//设置DaoMaster、DaoSession、Dao包名 + } } dependencies { @@ -68,8 +79,8 @@ //基础依赖库 implementation files('libs/lite-release.aar') implementation 'androidx.appcompat:appcompat:1.4.2' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' //Google官方授权框架 implementation 'pub.devrel:easypermissions:3.0.0' //腾讯Android UI框架 @@ -85,7 +96,7 @@ implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" //Kotlin协程 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' //图片加载框架 implementation 'com.github.bumptech.glide:glide:4.9.0' //图片选择框架 @@ -111,4 +122,9 @@ implementation group: 'com.hyman', name: 'flowlayout-lib', version: '1.1.2' //图片压缩 implementation 'top.zibin:Luban:1.1.8' + //推送SDK + implementation 'com.getui:gtsdk:3.2.10.0' //个推SDK + implementation 'com.getui:gtc:3.1.9.0' //个推核心组件 + //数据库框架 + implementation 'org.greenrobot:greendao:3.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e512ef..1d8f7de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + @@ -77,5 +80,24 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt index ce7a70e..219076d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ExpandableViewAdapter.kt @@ -30,13 +30,10 @@ } } - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): ExpandableItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExpandableItemViewHolder { + return ExpandableItemViewHolder( layoutInflater.inflate(R.layout.item_expand_view_rv, parent, false) - return ExpandableItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ExpandableItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt index b1021a4..c761aaa 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/HomeRecycleAdapter.kt @@ -10,13 +10,13 @@ import com.casic.app.smartwell.R import com.casic.app.smartwell.utils.LocaleConstant -class HomeRecycleAdapter(private val context: Context) : +class HomeRecycleAdapter(context: Context) : RecyclerView.Adapter() { + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = - LayoutInflater.from(context).inflate(R.layout.item_home_page_rv, parent, false) - return ItemViewHolder(view) + return ItemViewHolder(layoutInflater.inflate(R.layout.item_home_page_rv, parent, false)) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt new file mode 100644 index 0000000..185c45d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/NoticeDataAdapter.kt @@ -0,0 +1,71 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.NoticeLocaleBean + +class NoticeDataAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun getItemCount(): Int = dataRows.size + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_rv, parent, false)) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.dateView.text = rowsBean.noticeTime + holder.titleView.text = rowsBean.title + holder.contentView.text = rowsBean.content + val state = if (rowsBean.isRead == "0") { + View.VISIBLE + } else { + View.INVISIBLE + } + holder.readStateView.visibility = state + //绑定事件 + if (listener != null) { + holder.deleteView.setOnClickListener { + listener!!.onDeleteClicked(position) + } + + holder.showDetailLayout.setOnClickListener { + listener!!.onShowMoreClicked(position) + } + } + } + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var dateView: TextView = view.findViewById(R.id.dateView) + var titleView: TextView = view.findViewById(R.id.titleView) + var contentView: TextView = view.findViewById(R.id.contentView) + var readStateView: TextView = view.findViewById(R.id.readStateView) + + var showDetailLayout: LinearLayout = view.findViewById(R.id.showDetailLayout) + var deleteView: ImageView = view.findViewById(R.id.deleteView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onDeleteClicked(position: Int) + + fun onShowMoreClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt index 8374ac8..0e5f16c 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderCompletedAdapter.kt @@ -23,12 +23,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderCompletedAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_completed_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt index 5c3a8b7..4a0bef9 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderInHandleAdapter.kt @@ -23,17 +23,15 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): OrderInHandleAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_order_in_handle_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size - override fun onBindViewHolder(holder: OrderInHandleAdapter.ItemViewHolder, position: Int) { + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] holder.alarmContentView.text = rowsBean.alarmContentName diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt index e18fa97..ba36ad4 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotConfirmedAdapter.kt @@ -24,9 +24,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_confirmed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_confirmed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt index 9e7a70f..c15cb0f 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/OrderNotProcessedAdapter.kt @@ -18,9 +18,7 @@ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( - layoutInflater.inflate( - R.layout.item_order_not_processed_rv, parent, false - ) + layoutInflater.inflate(R.layout.item_order_not_processed_rv, parent, false) ) } diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt index 6220cd0..b7ce0ea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SearchResultAdapter.kt @@ -25,12 +25,10 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) private var isExpand = false - override fun onCreateViewHolder( - parent: ViewGroup, viewType: Int - ): SearchResultAdapter.ItemViewHolder { - val view: View = + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + return ItemViewHolder( layoutInflater.inflate(R.layout.item_search_result_rv, parent, false) - return ItemViewHolder(view) + ) } override fun getItemCount(): Int = dataRows.size diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt index 436850e..ef85439 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_sensor_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt index ee36ecf..93da00d 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -11,15 +11,15 @@ import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - private val context: Context, private val dataRows: MutableList + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_list_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt index eba34e5..05d8dea 100644 --- a/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellOperationAdapter.kt @@ -17,9 +17,9 @@ private var layoutInflater: LayoutInflater = LayoutInflater.from(context) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - val view: View = + return ItemViewHolder( layoutInflater.inflate(R.layout.item_well_operation_rv, parent, false) - return ItemViewHolder(view) + ) } override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt index 3a49995..30fa233 100644 --- a/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt +++ b/app/src/main/java/com/casic/app/smartwell/base/BaseApplication.kt @@ -1,20 +1,40 @@ package com.casic.app.smartwell.base import android.app.Application +import android.util.Log +import com.casic.app.smartwell.greendao.DaoMaster +import com.casic.app.smartwell.greendao.DaoSession +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.utils.SaveKeyValues import kotlin.properties.Delegates class BaseApplication : Application() { + private val kTag = "BaseApplication" + companion object { private var instance: BaseApplication by Delegates.notNull() fun obtainInstance() = instance + + private lateinit var daoSession: DaoSession } override fun onCreate() { super.onCreate() instance = this SaveKeyValues.initSharedPreferences(this) + //推送 + PushManager.getInstance().initialize(this) + PushManager.getInstance().setDebugLogger(this) { + Log.d(kTag, it) + } + val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartWell.db", null) + val daoMaster = DaoMaster(devOpenHelper.writableDatabase) + daoSession = daoMaster.newSession() + } + + fun obtainDaoSession(): DaoSession { + return daoSession } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt index 19a8631..fbf9dbc 100644 --- a/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/fragment/NoticePageFragment.kt @@ -1,11 +1,42 @@ package com.casic.app.smartwell.fragment +import android.os.CountDownTimer +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.NoticeDataAdapter +import com.casic.app.smartwell.extensions.showEmptyPage +import com.casic.app.smartwell.model.NoticeLocaleBean +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +import com.casic.app.smartwell.view.WellDetailActivity +import com.casic.app.smartwell.vm.DeviceViewModel +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseFragment +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.SaveKeyValues +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import kotlinx.android.synthetic.main.fragment_notice.* import kotlinx.android.synthetic.main.include_base_title.* +import kotlinx.android.synthetic.main.include_empty_view.* + class NoticePageFragment : KotlinBaseFragment() { + private val kTag = "NoticePageFragment" + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var userId: String + private lateinit var noticeDataAdapter: NoticeDataAdapter + private lateinit var deviceViewModel: DeviceViewModel + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 0 // 本地数据库分页从0开始 + private var isRefresh = false + private var isLoadMore = false + override fun initLayoutView(): Int = R.layout.fragment_notice override fun setupTopBarLayout() { @@ -13,10 +44,116 @@ } override fun initData() { + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, + object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + weakReferenceHandler = WeakReferenceHandler(callback) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + } + override fun onResume() { + //默认加载第一页 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + weakReferenceHandler.sendEmptyMessage(2022070401) + super.onResume() } override fun initEvent() { + noticeLayout.setOnRefreshListener { + isRefresh = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + } + + override fun onFinish() { + isRefresh = false + dataBeans.clear() + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + + it.finishRefresh() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + noticeLayout.setOnLoadMoreListener { + isLoadMore = true + object : CountDownTimer(1000, 500) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + isLoadMore = false + pageIndex++ + dataBeans.addAll( + DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + ) + it.finishLoadMore() + weakReferenceHandler.sendEmptyMessage(2022070401) + } + }.start() + } + + deviceViewModel.detailModel.observe(this, { + if (it.code == 200) { + if (it.data.rows.size > 0) { + val rowsBean = it.data.rows[0] + requireContext().navigatePageTo(rowsBean.wellId) + } else { + "无法查询到设备所在井信息".show(requireContext()) + } + } + }) + } + + private val callback = Handler.Callback { + if (it.what == 2022070401) { + if (isRefresh || isLoadMore) { + noticeDataAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("没有任何报警通知") { + pageIndex = 0 + dataBeans = DataBaseManager.instance.queryNoticeByPage(userId, pageIndex) + } + } else { + emptyView!!.hide() + noticeDataAdapter = NoticeDataAdapter(requireContext(), dataBeans) + noticeRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + noticeRecyclerView!!.adapter = noticeDataAdapter + noticeDataAdapter.setOnItemClickListener(object : + NoticeDataAdapter.OnItemClickListener { + override fun onDeleteClicked(position: Int) { + DataBaseManager.instance.deleteNoticeByMessageId(dataBeans[position].messageId) + dataBeans.removeAt(position) + noticeDataAdapter.notifyItemRemoved(position) + noticeDataAdapter.notifyItemRangeChanged( + position, dataBeans.size - position + ) + } + + override fun onShowMoreClicked(position: Int) { + deviceViewModel.obtainDeviceDetail(dataBeans[position].deviceCode) + //更改数据库里通知状态 + DataBaseManager.instance.updateNoticeByMessageId(dataBeans[position].messageId) + noticeDataAdapter.notifyItemChanged(position) + noticeDataAdapter.notifyItemRangeChanged( + position, + dataBeans.size - position + ) + } + }) + } + } + } + true } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java new file mode 100644 index 0000000..141eaca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoMaster.java @@ -0,0 +1,103 @@ +package com.casic.app.smartwell.greendao; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.util.Log; + +import org.greenrobot.greendao.AbstractDaoMaster; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseOpenHelper; +import org.greenrobot.greendao.database.StandardDatabase; +import org.greenrobot.greendao.identityscope.IdentityScopeType; + + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * Master of DAO (schema version 1): knows all DAOs. + */ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 1; + + /** + * Creates underlying database table using DAOs. + */ + public static void createAllTables(Database db, boolean ifNotExists) { + NoticeLocaleBeanDao.createTable(db, ifNotExists); + } + + /** + * Drops underlying database table using DAOs. + */ + public static void dropAllTables(Database db, boolean ifExists) { + NoticeLocaleBeanDao.dropTable(db, ifExists); + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + * Convenience method using a {@link DevOpenHelper}. + */ + public static DaoSession newDevSession(Context context, String name) { + Database db = new DevOpenHelper(context, name).getWritableDb(); + DaoMaster daoMaster = new DaoMaster(db); + return daoMaster.newSession(); + } + + public DaoMaster(SQLiteDatabase db) { + this(new StandardDatabase(db)); + } + + public DaoMaster(Database db) { + super(db, SCHEMA_VERSION); + registerDaoClass(NoticeLocaleBeanDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + + /** + * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - + */ + public static abstract class OpenHelper extends DatabaseOpenHelper { + public OpenHelper(Context context, String name) { + super(context, name, SCHEMA_VERSION); + } + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(Database db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name) { + super(context, name); + } + + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(Database db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java new file mode 100644 index 0000000..c574564 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/DaoSession.java @@ -0,0 +1,46 @@ +package com.casic.app.smartwell.greendao; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.AbstractDaoSession; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.identityscope.IdentityScopeType; +import org.greenrobot.greendao.internal.DaoConfig; + +import java.util.Map; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see org.greenrobot.greendao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig noticeLocaleBeanDaoConfig; + + private final NoticeLocaleBeanDao noticeLocaleBeanDao; + + public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> + daoConfigMap) { + super(db); + + noticeLocaleBeanDaoConfig = daoConfigMap.get(NoticeLocaleBeanDao.class).clone(); + noticeLocaleBeanDaoConfig.initIdentityScope(type); + + noticeLocaleBeanDao = new NoticeLocaleBeanDao(noticeLocaleBeanDaoConfig, this); + + registerDao(NoticeLocaleBean.class, noticeLocaleBeanDao); + } + + public void clear() { + noticeLocaleBeanDaoConfig.clearIdentityScope(); + } + + public NoticeLocaleBeanDao getNoticeLocaleBeanDao() { + return noticeLocaleBeanDao; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java new file mode 100644 index 0000000..2609600 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/greendao/NoticeLocaleBeanDao.java @@ -0,0 +1,260 @@ +package com.casic.app.smartwell.greendao; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; + +import com.casic.app.smartwell.model.NoticeLocaleBean; + +import org.greenrobot.greendao.AbstractDao; +import org.greenrobot.greendao.Property; +import org.greenrobot.greendao.database.Database; +import org.greenrobot.greendao.database.DatabaseStatement; +import org.greenrobot.greendao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * DAO for table "NOTICE_LOCALE_BEAN". + */ +public class NoticeLocaleBeanDao extends AbstractDao { + + public static final String TABLENAME = "NOTICE_LOCALE_BEAN"; + + /** + * Properties of entity NoticeLocaleBean.
+ * Can be used for QueryBuilder and for referencing column names. + */ + public static class Properties { + public final static Property Id = new Property(0, Long.class, "id", true, "_id"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property Appid = new Property(2, String.class, "appid", false, "APPID"); + public final static Property ClientId = new Property(3, String.class, "clientId", false, "CLIENT_ID"); + public final static Property TaskId = new Property(4, String.class, "taskId", false, "TASK_ID"); + public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID"); + public final static Property Title = new Property(6, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(7, String.class, "content", false, "CONTENT"); + public final static Property DeviceCode = new Property(8, String.class, "deviceCode", false, "DEVICE_CODE"); + public final static Property IsRead = new Property(9, String.class, "isRead", false, "IS_READ"); + public final static Property NoticeTime = new Property(10, String.class, "noticeTime", false, "NOTICE_TIME"); + } + + + public NoticeLocaleBeanDao(DaoConfig config) { + super(config); + } + + public NoticeLocaleBeanDao(DaoConfig config, DaoSession daoSession) { + super(config, daoSession); + } + + /** + * Creates the underlying database table. + */ + public static void createTable(Database db, boolean ifNotExists) { + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; + db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // + "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"APPID\" TEXT," + // 2: appid + "\"CLIENT_ID\" TEXT," + // 3: clientId + "\"TASK_ID\" TEXT," + // 4: taskId + "\"USER_ID\" TEXT," + // 5: userId + "\"TITLE\" TEXT," + // 6: title + "\"CONTENT\" TEXT," + // 7: content + "\"DEVICE_CODE\" TEXT," + // 8: deviceCode + "\"IS_READ\" TEXT," + // 9: isRead + "\"NOTICE_TIME\" TEXT);"); // 10: noticeTime + } + + /** + * Drops the underlying database table. + */ + public static void dropTable(Database db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"NOTICE_LOCALE_BEAN\""; + db.execSQL(sql); + } + + @Override + protected final void bindValues(DatabaseStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + protected final void bindValues(SQLiteStatement stmt, NoticeLocaleBean entity) { + stmt.clearBindings(); + + Long id = entity.getId(); + if (id != null) { + stmt.bindLong(1, id); + } + + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); + } + + String appid = entity.getAppid(); + if (appid != null) { + stmt.bindString(3, appid); + } + + String clientId = entity.getClientId(); + if (clientId != null) { + stmt.bindString(4, clientId); + } + + String taskId = entity.getTaskId(); + if (taskId != null) { + stmt.bindString(5, taskId); + } + + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(6, userId); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(7, title); + } + + String content = entity.getContent(); + if (content != null) { + stmt.bindString(8, content); + } + + String deviceCode = entity.getDeviceCode(); + if (deviceCode != null) { + stmt.bindString(9, deviceCode); + } + + String isRead = entity.getIsRead(); + if (isRead != null) { + stmt.bindString(10, isRead); + } + + String noticeTime = entity.getNoticeTime(); + if (noticeTime != null) { + stmt.bindString(11, noticeTime); + } + } + + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); + } + + @Override + public NoticeLocaleBean readEntity(Cursor cursor, int offset) { + NoticeLocaleBean entity = new NoticeLocaleBean( // + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // appid + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // clientId + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // taskId + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // userId + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // content + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // deviceCode + cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // isRead + cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // noticeTime + ); + return entity; + } + + @Override + public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { + entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setAppid(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setClientId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setTaskId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setContent(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setDeviceCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); + entity.setIsRead(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); + entity.setNoticeTime(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); + } + + @Override + protected final Long updateKeyAfterInsert(NoticeLocaleBean entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + @Override + public Long getKey(NoticeLocaleBean entity) { + if (entity != null) { + return entity.getId(); + } else { + return null; + } + } + + @Override + public boolean hasKey(NoticeLocaleBean entity) { + return entity.getId() != null; + } + + @Override + protected final boolean isEntityUpdateable() { + return true; + } + +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java new file mode 100644 index 0000000..d77b700 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/DeviceDetailModel.java @@ -0,0 +1,274 @@ +package com.casic.app.smartwell.model; + +import java.util.List; + +public class DeviceDetailModel { + + private int code; + private DataBean data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private List rows; + private int total; + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public static class RowsBean { + private String bfzt; + private String bfztName; + private String communication; + private String concenCode; + private String concenId; + private String deptName; + private String deptid; + private String devcode; + private String deviceName; + private String deviceType; + private String deviceTypeName; + private String id; + private String installDate; + private String modelId; + private String modelName; + private String onlineState; + private String onlineStateName; + private String position; + private String ts; + private String valid; + private String watchType; + private String wellCode; + private String wellId; + + public String getBfzt() { + return bfzt; + } + + public void setBfzt(String bfzt) { + this.bfzt = bfzt; + } + + public String getBfztName() { + return bfztName; + } + + public void setBfztName(String bfztName) { + this.bfztName = bfztName; + } + + public String getCommunication() { + return communication; + } + + public void setCommunication(String communication) { + this.communication = communication; + } + + public String getConcenCode() { + return concenCode; + } + + public void setConcenCode(String concenCode) { + this.concenCode = concenCode; + } + + public String getConcenId() { + return concenId; + } + + public void setConcenId(String concenId) { + this.concenId = concenId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getDeviceTypeName() { + return deviceTypeName; + } + + public void setDeviceTypeName(String deviceTypeName) { + this.deviceTypeName = deviceTypeName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getInstallDate() { + return installDate; + } + + public void setInstallDate(String installDate) { + this.installDate = installDate; + } + + public String getModelId() { + return modelId; + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + + public String getOnlineStateName() { + return onlineStateName; + } + + public void setOnlineStateName(String onlineStateName) { + this.onlineStateName = onlineStateName; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getValid() { + return valid; + } + + public void setValid(String valid) { + this.valid = valid; + } + + public String getWatchType() { + return watchType; + } + + public void setWatchType(String watchType) { + this.watchType = watchType; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getWellId() { + return wellId; + } + + public void setWellId(String wellId) { + this.wellId = wellId; + } + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java new file mode 100644 index 0000000..25e2528 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/NoticeLocaleBean.java @@ -0,0 +1,133 @@ +package com.casic.app.smartwell.model; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Generated; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; + +@Entity +public class NoticeLocaleBean { + @Id(autoincrement = true) + private Long id;//主键自增 + + @Unique + private String messageId; + private String appid; + private String clientId; + private String taskId; + private String userId; + private String title; + private String content; + private String deviceCode; + private String isRead;//0-未读,1-已读 + private String noticeTime; + + @Generated(hash = 2043931173) + public NoticeLocaleBean(Long id, String messageId, String appid, + String clientId, String taskId, String userId, String title, + String content, String deviceCode, String isRead, String noticeTime) { + this.id = id; + this.messageId = messageId; + this.appid = appid; + this.clientId = clientId; + this.taskId = taskId; + this.userId = userId; + this.title = title; + this.content = content; + this.deviceCode = deviceCode; + this.isRead = isRead; + this.noticeTime = noticeTime; + } + + @Generated(hash = 1054075554) + public NoticeLocaleBean() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getAppid() { + return this.appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getClientId() { + return this.clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getTaskId() { + return this.taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getDeviceCode() { + return this.deviceCode; + } + + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } + + public String getIsRead() { + return this.isRead; + } + + public void setIsRead(String isRead) { + this.isRead = isRead; + } + + public String getNoticeTime() { + return this.noticeTime; + } + + public void setNoticeTime(String noticeTime) { + this.noticeTime = noticeTime; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt new file mode 100644 index 0000000..6e7fc1c --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/ApplicationPushService.kt @@ -0,0 +1,5 @@ +package com.casic.app.smartwell.service + +import com.igexin.sdk.PushService + +class ApplicationPushService : PushService() \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt new file mode 100644 index 0000000..88a01bb --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/service/SmartWellIntentService.kt @@ -0,0 +1,81 @@ +package com.casic.app.smartwell.service + +import android.content.Context +import android.util.Log +import com.casic.app.smartwell.model.UserDetailModel +import com.casic.app.smartwell.utils.DataBaseManager +import com.casic.app.smartwell.utils.LocaleConstant +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 +import com.pengxh.kt.lite.extensions.timestampToCompleteDate +import com.pengxh.kt.lite.extensions.toJson +import com.pengxh.kt.lite.utils.SaveKeyValues + +class SmartWellIntentService : GTIntentService() { + + private val kTag = "SmartWellIntentService" + + override fun onReceiveServicePid(context: Context?, pid: Int) { + + } + + // 透传消息 + override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) { + Log.d(kTag, "透传消息 -> msg = $msg") + } + + // 接收 cid + override fun onReceiveClientId(context: Context?, clientid: String?) { + Log.d(kTag, "onReceiveClientId -> clientid = $clientid") + } + + // cid 离线上线通知 + override fun onReceiveOnlineState(context: Context?, online: Boolean) { + + } + + // 各种事件处理回执 + override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) { + + } + + // 通知到达 + override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) { +// { +// "content": "设备编号412019010210发生井盖开盖报警", +// "messageId": "3b45d3dbc2d64b958bc5c702eea13769", +// "taskId": "TEST_0704_1e04163d440384f8d9968b32a0857abf", +// "title": "新消息来了", +// "appid": "HKv8K9qARd6WckZ1o2Vbu4", +// "clientId": "cea3a200851c7b8e6a7f8244b5362bf4", +// "pkgName": "com.casic.app.smartwell" +// } + if (msg == null) { + return + } + Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}") + val userDetailJson = SaveKeyValues.getValue(LocaleConstant.USER_DETAIL_MODEL, "") as String + var userId = "" + if (userDetailJson.isNotBlank()) { + val userDataModel = Gson().fromJson( + userDetailJson, object : TypeToken() {}.type + ) + userId = userDataModel.id.toString() + } + val deviceCode = msg.content.substring(4, 16) + DataBaseManager.instance.insertNotice( + msg.messageId, msg.appid, msg.clientId, msg.taskId, + userId, msg.title, msg.content, deviceCode, "0", + System.currentTimeMillis().timestampToCompleteDate() + ) + } + + // 通知点击 + override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) { + Log.d(kTag, "通知点击 -> msg = $msg") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt new file mode 100644 index 0000000..801dd88 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/utils/DataBaseManager.kt @@ -0,0 +1,63 @@ +package com.casic.app.smartwell.utils + +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.greendao.NoticeLocaleBeanDao +import com.casic.app.smartwell.model.NoticeLocaleBean + +class DataBaseManager private constructor() { + + companion object { + //Kotlin委托模式双重锁单例 + val instance: DataBaseManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { + DataBaseManager() + } + } + + private val beanDao = BaseApplication.obtainInstance().obtainDaoSession().noticeLocaleBeanDao + + fun insertNotice( + messageId: String, appid: String, clientId: String, + taskId: String, userId: String, title: String, + content: String, deviceCode: String, isRead: String, + noticeTime: String + ) { + val noticeLocaleBean = NoticeLocaleBean() + noticeLocaleBean.messageId = messageId + noticeLocaleBean.appid = appid + noticeLocaleBean.clientId = clientId + noticeLocaleBean.taskId = taskId + noticeLocaleBean.userId = userId + noticeLocaleBean.title = title + noticeLocaleBean.content = content + noticeLocaleBean.deviceCode = deviceCode + noticeLocaleBean.isRead = isRead + noticeLocaleBean.noticeTime = noticeTime + beanDao.insert(noticeLocaleBean) + } + + fun deleteNoticeByMessageId(messageId: String) { + val result = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list() + beanDao.deleteInTx(result) + } + + fun updateNoticeByMessageId(messageId: String) { + val noticeLocaleBean = beanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique() ?: return + noticeLocaleBean.isRead = "1" + beanDao.update(noticeLocaleBean) + } + + + fun queryNoticeByPage(userId: String, offset: Int): MutableList { + return BaseApplication.obtainInstance().obtainDaoSession() + .queryBuilder(NoticeLocaleBean::class.java) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.NoticeTime) + .limit(LocaleConstant.PAGE_LIMIT) + .list() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index b905e8f..c6b5e70 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -302,4 +302,13 @@ */ @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String + + /** + * 获取设备详情 + */ + @GET("/device/list") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Query("deviceCode") deviceCode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index b8414d5..d2859fc 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -257,4 +257,11 @@ suspend fun updateVersion(): String { return api.obtainVersionResult(AuthenticationHelper.token!!) } + + /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(deviceCode: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, deviceCode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt index 996d0fd..006a9fe 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/MainActivity.kt @@ -11,6 +11,7 @@ import com.casic.app.smartwell.fragment.NoticePageFragment import com.casic.app.smartwell.fragment.OrderListFragment import com.gyf.immersionbar.ImmersionBar +import com.igexin.sdk.PushManager import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.show @@ -38,7 +39,8 @@ } override fun initData() { - + //推送,多次调用 SDK 初始化并无影响。 + PushManager.getInstance().initialize(this) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt new file mode 100644 index 0000000..59f7960 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/DeviceViewModel.kt @@ -0,0 +1,33 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseApplication +import com.casic.app.smartwell.extensions.separateResponseCode +import com.casic.app.smartwell.extensions.toErrorMessage +import com.casic.app.smartwell.model.DeviceDetailModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.pengxh.kt.lite.extensions.launch +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.vm.BaseViewModel + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val detailModel = MutableLiveData() + + fun obtainDeviceDetail(deviceCode: String) = launch({ + val response = RetrofitServiceManager.obtainDeviceDetail(deviceCode) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + detailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/push.png b/app/src/main/res/drawable-hdpi/push.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-hdpi/push_small.png b/app/src/main/res/drawable-hdpi/push_small.png new file mode 100644 index 0000000..4e45ae2 --- /dev/null +++ b/app/src/main/res/drawable-hdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push.png b/app/src/main/res/drawable-ldpi/push.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-ldpi/push_small.png b/app/src/main/res/drawable-ldpi/push_small.png new file mode 100644 index 0000000..ea3ec50 --- /dev/null +++ b/app/src/main/res/drawable-ldpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push.png b/app/src/main/res/drawable-mdpi/push.png new file mode 100644 index 0000000..48893cf --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-mdpi/push_small.png b/app/src/main/res/drawable-mdpi/push_small.png new file mode 100644 index 0000000..2490a93 --- /dev/null +++ b/app/src/main/res/drawable-mdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push.png b/app/src/main/res/drawable-xhdpi/push.png new file mode 100644 index 0000000..2aa5d02 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xhdpi/push_small.png b/app/src/main/res/drawable-xhdpi/push_small.png new file mode 100644 index 0000000..4b8a195 --- /dev/null +++ b/app/src/main/res/drawable-xhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push.png b/app/src/main/res/drawable-xxhdpi/push.png new file mode 100644 index 0000000..57056be --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxhdpi/push_small.png b/app/src/main/res/drawable-xxhdpi/push_small.png new file mode 100644 index 0000000..dd40d82 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push.png b/app/src/main/res/drawable-xxxhdpi/push.png new file mode 100644 index 0000000..9b01303 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push.png Binary files differ diff --git a/app/src/main/res/drawable-xxxhdpi/push_small.png b/app/src/main/res/drawable-xxxhdpi/push_small.png new file mode 100644 index 0000000..18a80d0 --- /dev/null +++ b/app/src/main/res/drawable-xxxhdpi/push_small.png Binary files differ diff --git a/app/src/main/res/drawable/dash_line_gray.xml b/app/src/main/res/drawable/dash_line_gray.xml new file mode 100644 index 0000000..61ca4c0 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_gray.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dot_red.xml b/app/src/main/res/drawable/dot_red.xml new file mode 100644 index 0000000..fa97466 --- /dev/null +++ b/app/src/main/res/drawable/dot_red.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_alarm_tag.xml b/app/src/main/res/drawable/ic_alarm_tag.xml new file mode 100644 index 0000000..8650128 --- /dev/null +++ b/app/src/main/res/drawable/ic_alarm_tag.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/src/main/res/layout/fragment_mine.xml b/app/src/main/res/layout/fragment_mine.xml index 8ede317..e672c7e 100644 --- a/app/src/main/res/layout/fragment_mine.xml +++ b/app/src/main/res/layout/fragment_mine.xml @@ -89,6 +89,23 @@ android:textColorLink="@color/mainThemeColor" android:textSize="@dimen/sp_16" /> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_notice.xml b/app/src/main/res/layout/fragment_notice.xml index 7015d7b..aece8b8 100644 --- a/app/src/main/res/layout/fragment_notice.xml +++ b/app/src/main/res/layout/fragment_notice.xml @@ -7,4 +7,37 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_notice_rv.xml b/app/src/main/res/layout/item_notice_rv.xml new file mode 100644 index 0000000..c54568c --- /dev/null +++ b/app/src/main/res/layout/item_notice_rv.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3c00441..6894b35 100644 --- a/build.gradle +++ b/build.gradle @@ -7,8 +7,9 @@ google() } dependencies { - classpath 'com.android.tools.build:gradle:3.6.3' + classpath 'com.android.tools.build:gradle:3.6.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -21,6 +22,7 @@ //依赖库 maven { url 'https://jitpack.io' } google() + maven { url "https://mvn.getui.com/nexus/content/repositories/releases/"} } }