diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java index 98e8df8..02492d7 100644 --- a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java +++ b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java @@ -2,11 +2,15 @@ import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.MapConfigBean; +import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.bean.ToiletListBean; import com.casic.dcms.greendao.MapConfigBeanDao; +import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.greendao.ToiletListBeanDao; import com.casic.dcms.mvvm.model.MapConfigModel; import com.casic.dcms.mvvm.model.ToiletListModel; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; import java.util.ArrayList; import java.util.List; @@ -31,12 +35,66 @@ return instance; } + private final NoticeLocaleBeanDao noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); private final MapConfigBeanDao mapConfigBeanDao = BaseApplication.getDaoSession().getMapConfigBeanDao(); private final ToiletListBeanDao toiletListBeanDao = BaseApplication.getDaoSession().getToiletListBeanDao(); /***路灯本地数据管理************************************************************/ /***通知本地数据管理************************************************************/ + public void savePushNotice(NoticeLocaleBean noticeBean) { + noticeBeanDao.save(noticeBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public int queryUnReadNotice() { + return noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.IsRead.eq("1") + ).list().size(); + } + + public List queryNoticeByPage(String userId, int offset) { + return BaseApplication.getDaoSession() + .queryBuilder(NoticeLocaleBean.class) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) + .limit(LocaleConstant.PAGE_LIMIT) + .list(); + } + + public void deleteNoticeByMessageId(String messageId) { + List result = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list(); + noticeBeanDao.deleteInTx(result); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public void updateNoticeByMessageId(String messageId) { + NoticeLocaleBean noticeLocaleBean = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique(); + noticeLocaleBean.setIsRead("0"); + noticeBeanDao.update(noticeLocaleBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + /***地图本地数据管理************************************************************/ public void deleteAllMapConfig() { diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java index 98e8df8..02492d7 100644 --- a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java +++ b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java @@ -2,11 +2,15 @@ import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.MapConfigBean; +import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.bean.ToiletListBean; import com.casic.dcms.greendao.MapConfigBeanDao; +import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.greendao.ToiletListBeanDao; import com.casic.dcms.mvvm.model.MapConfigModel; import com.casic.dcms.mvvm.model.ToiletListModel; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; import java.util.ArrayList; import java.util.List; @@ -31,12 +35,66 @@ return instance; } + private final NoticeLocaleBeanDao noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); private final MapConfigBeanDao mapConfigBeanDao = BaseApplication.getDaoSession().getMapConfigBeanDao(); private final ToiletListBeanDao toiletListBeanDao = BaseApplication.getDaoSession().getToiletListBeanDao(); /***路灯本地数据管理************************************************************/ /***通知本地数据管理************************************************************/ + public void savePushNotice(NoticeLocaleBean noticeBean) { + noticeBeanDao.save(noticeBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public int queryUnReadNotice() { + return noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.IsRead.eq("1") + ).list().size(); + } + + public List queryNoticeByPage(String userId, int offset) { + return BaseApplication.getDaoSession() + .queryBuilder(NoticeLocaleBean.class) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) + .limit(LocaleConstant.PAGE_LIMIT) + .list(); + } + + public void deleteNoticeByMessageId(String messageId) { + List result = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list(); + noticeBeanDao.deleteInTx(result); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public void updateNoticeByMessageId(String messageId) { + NoticeLocaleBean noticeLocaleBean = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique(); + noticeLocaleBean.setIsRead("0"); + noticeBeanDao.update(noticeLocaleBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + /***地图本地数据管理************************************************************/ public void deleteAllMapConfig() { diff --git a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java index e7ace6d..90f5796 100644 --- a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java +++ b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java @@ -59,11 +59,10 @@ public static final int CASE_HANDLE = 0; public static final int CASE_VERIFY = 1; public static final int CASE_CHECK = 2; - public static final int PUSH_REGISTER = 11; - public static final int PUSH_MESSAGE_DATA = 12;//透传消息,包含消息的详细数据 - public static final int PUSH_CREATE_NOTIFICATION = 13; - public static final int UPLOAD_LOCATION = 14; - public static final int MESSAGE_NUMBER = 15; + public static final int PUSH_REGISTER = 2022080101; + public static final int UPDATE_NOTICE_FRAGMENT = 2022080102; + public static final int MESSAGE_NUMBER = 2022080103; + public static final int UPDATE_LOCATION = 2022080201; public static final double DEFAULT_LNG = 116.05695247650146; public static final double DEFAULT_LAT = 27.76725390642336; diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java index 98e8df8..02492d7 100644 --- a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java +++ b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java @@ -2,11 +2,15 @@ import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.MapConfigBean; +import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.bean.ToiletListBean; import com.casic.dcms.greendao.MapConfigBeanDao; +import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.greendao.ToiletListBeanDao; import com.casic.dcms.mvvm.model.MapConfigModel; import com.casic.dcms.mvvm.model.ToiletListModel; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; import java.util.ArrayList; import java.util.List; @@ -31,12 +35,66 @@ return instance; } + private final NoticeLocaleBeanDao noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); private final MapConfigBeanDao mapConfigBeanDao = BaseApplication.getDaoSession().getMapConfigBeanDao(); private final ToiletListBeanDao toiletListBeanDao = BaseApplication.getDaoSession().getToiletListBeanDao(); /***路灯本地数据管理************************************************************/ /***通知本地数据管理************************************************************/ + public void savePushNotice(NoticeLocaleBean noticeBean) { + noticeBeanDao.save(noticeBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public int queryUnReadNotice() { + return noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.IsRead.eq("1") + ).list().size(); + } + + public List queryNoticeByPage(String userId, int offset) { + return BaseApplication.getDaoSession() + .queryBuilder(NoticeLocaleBean.class) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) + .limit(LocaleConstant.PAGE_LIMIT) + .list(); + } + + public void deleteNoticeByMessageId(String messageId) { + List result = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list(); + noticeBeanDao.deleteInTx(result); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public void updateNoticeByMessageId(String messageId) { + NoticeLocaleBean noticeLocaleBean = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique(); + noticeLocaleBean.setIsRead("0"); + noticeBeanDao.update(noticeLocaleBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + /***地图本地数据管理************************************************************/ public void deleteAllMapConfig() { diff --git a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java index e7ace6d..90f5796 100644 --- a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java +++ b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java @@ -59,11 +59,10 @@ public static final int CASE_HANDLE = 0; public static final int CASE_VERIFY = 1; public static final int CASE_CHECK = 2; - public static final int PUSH_REGISTER = 11; - public static final int PUSH_MESSAGE_DATA = 12;//透传消息,包含消息的详细数据 - public static final int PUSH_CREATE_NOTIFICATION = 13; - public static final int UPLOAD_LOCATION = 14; - public static final int MESSAGE_NUMBER = 15; + public static final int PUSH_REGISTER = 2022080101; + public static final int UPDATE_NOTICE_FRAGMENT = 2022080102; + public static final int MESSAGE_NUMBER = 2022080103; + public static final int UPDATE_LOCATION = 2022080201; public static final double DEFAULT_LNG = 116.05695247650146; public static final double DEFAULT_LAT = 27.76725390642336; 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/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java index 98e8df8..02492d7 100644 --- a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java +++ b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java @@ -2,11 +2,15 @@ import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.MapConfigBean; +import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.bean.ToiletListBean; import com.casic.dcms.greendao.MapConfigBeanDao; +import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.greendao.ToiletListBeanDao; import com.casic.dcms.mvvm.model.MapConfigModel; import com.casic.dcms.mvvm.model.ToiletListModel; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; import java.util.ArrayList; import java.util.List; @@ -31,12 +35,66 @@ return instance; } + private final NoticeLocaleBeanDao noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); private final MapConfigBeanDao mapConfigBeanDao = BaseApplication.getDaoSession().getMapConfigBeanDao(); private final ToiletListBeanDao toiletListBeanDao = BaseApplication.getDaoSession().getToiletListBeanDao(); /***路灯本地数据管理************************************************************/ /***通知本地数据管理************************************************************/ + public void savePushNotice(NoticeLocaleBean noticeBean) { + noticeBeanDao.save(noticeBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public int queryUnReadNotice() { + return noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.IsRead.eq("1") + ).list().size(); + } + + public List queryNoticeByPage(String userId, int offset) { + return BaseApplication.getDaoSession() + .queryBuilder(NoticeLocaleBean.class) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) + .limit(LocaleConstant.PAGE_LIMIT) + .list(); + } + + public void deleteNoticeByMessageId(String messageId) { + List result = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list(); + noticeBeanDao.deleteInTx(result); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public void updateNoticeByMessageId(String messageId) { + NoticeLocaleBean noticeLocaleBean = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique(); + noticeLocaleBean.setIsRead("0"); + noticeBeanDao.update(noticeLocaleBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + /***地图本地数据管理************************************************************/ public void deleteAllMapConfig() { diff --git a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java index e7ace6d..90f5796 100644 --- a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java +++ b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java @@ -59,11 +59,10 @@ public static final int CASE_HANDLE = 0; public static final int CASE_VERIFY = 1; public static final int CASE_CHECK = 2; - public static final int PUSH_REGISTER = 11; - public static final int PUSH_MESSAGE_DATA = 12;//透传消息,包含消息的详细数据 - public static final int PUSH_CREATE_NOTIFICATION = 13; - public static final int UPLOAD_LOCATION = 14; - public static final int MESSAGE_NUMBER = 15; + public static final int PUSH_REGISTER = 2022080101; + public static final int UPDATE_NOTICE_FRAGMENT = 2022080102; + public static final int MESSAGE_NUMBER = 2022080103; + public static final int UPDATE_LOCATION = 2022080201; public static final double DEFAULT_LNG = 116.05695247650146; public static final double DEFAULT_LAT = 27.76725390642336; 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..63ef2c4 --- /dev/null +++ b/app/src/main/res/drawable/dot_red.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java index 98e8df8..02492d7 100644 --- a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java +++ b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java @@ -2,11 +2,15 @@ import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.MapConfigBean; +import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.bean.ToiletListBean; import com.casic.dcms.greendao.MapConfigBeanDao; +import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.greendao.ToiletListBeanDao; import com.casic.dcms.mvvm.model.MapConfigModel; import com.casic.dcms.mvvm.model.ToiletListModel; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; import java.util.ArrayList; import java.util.List; @@ -31,12 +35,66 @@ return instance; } + private final NoticeLocaleBeanDao noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); private final MapConfigBeanDao mapConfigBeanDao = BaseApplication.getDaoSession().getMapConfigBeanDao(); private final ToiletListBeanDao toiletListBeanDao = BaseApplication.getDaoSession().getToiletListBeanDao(); /***路灯本地数据管理************************************************************/ /***通知本地数据管理************************************************************/ + public void savePushNotice(NoticeLocaleBean noticeBean) { + noticeBeanDao.save(noticeBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public int queryUnReadNotice() { + return noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.IsRead.eq("1") + ).list().size(); + } + + public List queryNoticeByPage(String userId, int offset) { + return BaseApplication.getDaoSession() + .queryBuilder(NoticeLocaleBean.class) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) + .limit(LocaleConstant.PAGE_LIMIT) + .list(); + } + + public void deleteNoticeByMessageId(String messageId) { + List result = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list(); + noticeBeanDao.deleteInTx(result); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public void updateNoticeByMessageId(String messageId) { + NoticeLocaleBean noticeLocaleBean = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique(); + noticeLocaleBean.setIsRead("0"); + noticeBeanDao.update(noticeLocaleBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + /***地图本地数据管理************************************************************/ public void deleteAllMapConfig() { diff --git a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java index e7ace6d..90f5796 100644 --- a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java +++ b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java @@ -59,11 +59,10 @@ public static final int CASE_HANDLE = 0; public static final int CASE_VERIFY = 1; public static final int CASE_CHECK = 2; - public static final int PUSH_REGISTER = 11; - public static final int PUSH_MESSAGE_DATA = 12;//透传消息,包含消息的详细数据 - public static final int PUSH_CREATE_NOTIFICATION = 13; - public static final int UPLOAD_LOCATION = 14; - public static final int MESSAGE_NUMBER = 15; + public static final int PUSH_REGISTER = 2022080101; + public static final int UPDATE_NOTICE_FRAGMENT = 2022080102; + public static final int MESSAGE_NUMBER = 2022080103; + public static final int UPDATE_LOCATION = 2022080201; public static final double DEFAULT_LNG = 116.05695247650146; public static final double DEFAULT_LAT = 27.76725390642336; 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..63ef2c4 --- /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/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java index 98e8df8..02492d7 100644 --- a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java +++ b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java @@ -2,11 +2,15 @@ import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.MapConfigBean; +import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.bean.ToiletListBean; import com.casic.dcms.greendao.MapConfigBeanDao; +import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.greendao.ToiletListBeanDao; import com.casic.dcms.mvvm.model.MapConfigModel; import com.casic.dcms.mvvm.model.ToiletListModel; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; import java.util.ArrayList; import java.util.List; @@ -31,12 +35,66 @@ return instance; } + private final NoticeLocaleBeanDao noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); private final MapConfigBeanDao mapConfigBeanDao = BaseApplication.getDaoSession().getMapConfigBeanDao(); private final ToiletListBeanDao toiletListBeanDao = BaseApplication.getDaoSession().getToiletListBeanDao(); /***路灯本地数据管理************************************************************/ /***通知本地数据管理************************************************************/ + public void savePushNotice(NoticeLocaleBean noticeBean) { + noticeBeanDao.save(noticeBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public int queryUnReadNotice() { + return noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.IsRead.eq("1") + ).list().size(); + } + + public List queryNoticeByPage(String userId, int offset) { + return BaseApplication.getDaoSession() + .queryBuilder(NoticeLocaleBean.class) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) + .limit(LocaleConstant.PAGE_LIMIT) + .list(); + } + + public void deleteNoticeByMessageId(String messageId) { + List result = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list(); + noticeBeanDao.deleteInTx(result); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public void updateNoticeByMessageId(String messageId) { + NoticeLocaleBean noticeLocaleBean = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique(); + noticeLocaleBean.setIsRead("0"); + noticeBeanDao.update(noticeLocaleBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + /***地图本地数据管理************************************************************/ public void deleteAllMapConfig() { diff --git a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java index e7ace6d..90f5796 100644 --- a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java +++ b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java @@ -59,11 +59,10 @@ public static final int CASE_HANDLE = 0; public static final int CASE_VERIFY = 1; public static final int CASE_CHECK = 2; - public static final int PUSH_REGISTER = 11; - public static final int PUSH_MESSAGE_DATA = 12;//透传消息,包含消息的详细数据 - public static final int PUSH_CREATE_NOTIFICATION = 13; - public static final int UPLOAD_LOCATION = 14; - public static final int MESSAGE_NUMBER = 15; + public static final int PUSH_REGISTER = 2022080101; + public static final int UPDATE_NOTICE_FRAGMENT = 2022080102; + public static final int MESSAGE_NUMBER = 2022080103; + public static final int UPDATE_LOCATION = 2022080201; public static final double DEFAULT_LNG = 116.05695247650146; public static final double DEFAULT_LAT = 27.76725390642336; 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..63ef2c4 --- /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/drawable/ic_delete.xml b/app/src/main/res/drawable/ic_delete.xml new file mode 100644 index 0000000..ef661b6 --- /dev/null +++ b/app/src/main/res/drawable/ic_delete.xml @@ -0,0 +1,12 @@ + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java index 98e8df8..02492d7 100644 --- a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java +++ b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java @@ -2,11 +2,15 @@ import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.MapConfigBean; +import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.bean.ToiletListBean; import com.casic.dcms.greendao.MapConfigBeanDao; +import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.greendao.ToiletListBeanDao; import com.casic.dcms.mvvm.model.MapConfigModel; import com.casic.dcms.mvvm.model.ToiletListModel; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; import java.util.ArrayList; import java.util.List; @@ -31,12 +35,66 @@ return instance; } + private final NoticeLocaleBeanDao noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); private final MapConfigBeanDao mapConfigBeanDao = BaseApplication.getDaoSession().getMapConfigBeanDao(); private final ToiletListBeanDao toiletListBeanDao = BaseApplication.getDaoSession().getToiletListBeanDao(); /***路灯本地数据管理************************************************************/ /***通知本地数据管理************************************************************/ + public void savePushNotice(NoticeLocaleBean noticeBean) { + noticeBeanDao.save(noticeBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public int queryUnReadNotice() { + return noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.IsRead.eq("1") + ).list().size(); + } + + public List queryNoticeByPage(String userId, int offset) { + return BaseApplication.getDaoSession() + .queryBuilder(NoticeLocaleBean.class) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) + .limit(LocaleConstant.PAGE_LIMIT) + .list(); + } + + public void deleteNoticeByMessageId(String messageId) { + List result = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list(); + noticeBeanDao.deleteInTx(result); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public void updateNoticeByMessageId(String messageId) { + NoticeLocaleBean noticeLocaleBean = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique(); + noticeLocaleBean.setIsRead("0"); + noticeBeanDao.update(noticeLocaleBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + /***地图本地数据管理************************************************************/ public void deleteAllMapConfig() { diff --git a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java index e7ace6d..90f5796 100644 --- a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java +++ b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java @@ -59,11 +59,10 @@ public static final int CASE_HANDLE = 0; public static final int CASE_VERIFY = 1; public static final int CASE_CHECK = 2; - public static final int PUSH_REGISTER = 11; - public static final int PUSH_MESSAGE_DATA = 12;//透传消息,包含消息的详细数据 - public static final int PUSH_CREATE_NOTIFICATION = 13; - public static final int UPLOAD_LOCATION = 14; - public static final int MESSAGE_NUMBER = 15; + public static final int PUSH_REGISTER = 2022080101; + public static final int UPDATE_NOTICE_FRAGMENT = 2022080102; + public static final int MESSAGE_NUMBER = 2022080103; + public static final int UPDATE_LOCATION = 2022080201; public static final double DEFAULT_LNG = 116.05695247650146; public static final double DEFAULT_LAT = 27.76725390642336; 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..63ef2c4 --- /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/drawable/ic_delete.xml b/app/src/main/res/drawable/ic_delete.xml new file mode 100644 index 0000000..ef661b6 --- /dev/null +++ b/app/src/main/res/drawable/ic_delete.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 8536010..5a8203f 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -13,7 +13,7 @@ android:layout_width="128dp" android:layout_height="128dp" android:layout_centerInParent="true" - android:src="@mipmap/ic_launcher" /> + android:src="@mipmap/app_logo" /> + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java index 98e8df8..02492d7 100644 --- a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java +++ b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java @@ -2,11 +2,15 @@ import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.MapConfigBean; +import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.bean.ToiletListBean; import com.casic.dcms.greendao.MapConfigBeanDao; +import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.greendao.ToiletListBeanDao; import com.casic.dcms.mvvm.model.MapConfigModel; import com.casic.dcms.mvvm.model.ToiletListModel; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; import java.util.ArrayList; import java.util.List; @@ -31,12 +35,66 @@ return instance; } + private final NoticeLocaleBeanDao noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); private final MapConfigBeanDao mapConfigBeanDao = BaseApplication.getDaoSession().getMapConfigBeanDao(); private final ToiletListBeanDao toiletListBeanDao = BaseApplication.getDaoSession().getToiletListBeanDao(); /***路灯本地数据管理************************************************************/ /***通知本地数据管理************************************************************/ + public void savePushNotice(NoticeLocaleBean noticeBean) { + noticeBeanDao.save(noticeBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public int queryUnReadNotice() { + return noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.IsRead.eq("1") + ).list().size(); + } + + public List queryNoticeByPage(String userId, int offset) { + return BaseApplication.getDaoSession() + .queryBuilder(NoticeLocaleBean.class) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) + .limit(LocaleConstant.PAGE_LIMIT) + .list(); + } + + public void deleteNoticeByMessageId(String messageId) { + List result = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list(); + noticeBeanDao.deleteInTx(result); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public void updateNoticeByMessageId(String messageId) { + NoticeLocaleBean noticeLocaleBean = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique(); + noticeLocaleBean.setIsRead("0"); + noticeBeanDao.update(noticeLocaleBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + /***地图本地数据管理************************************************************/ public void deleteAllMapConfig() { diff --git a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java index e7ace6d..90f5796 100644 --- a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java +++ b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java @@ -59,11 +59,10 @@ public static final int CASE_HANDLE = 0; public static final int CASE_VERIFY = 1; public static final int CASE_CHECK = 2; - public static final int PUSH_REGISTER = 11; - public static final int PUSH_MESSAGE_DATA = 12;//透传消息,包含消息的详细数据 - public static final int PUSH_CREATE_NOTIFICATION = 13; - public static final int UPLOAD_LOCATION = 14; - public static final int MESSAGE_NUMBER = 15; + public static final int PUSH_REGISTER = 2022080101; + public static final int UPDATE_NOTICE_FRAGMENT = 2022080102; + public static final int MESSAGE_NUMBER = 2022080103; + public static final int UPDATE_LOCATION = 2022080201; public static final double DEFAULT_LNG = 116.05695247650146; public static final double DEFAULT_LAT = 27.76725390642336; 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..63ef2c4 --- /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/drawable/ic_delete.xml b/app/src/main/res/drawable/ic_delete.xml new file mode 100644 index 0000000..ef661b6 --- /dev/null +++ b/app/src/main/res/drawable/ic_delete.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 8536010..5a8203f 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -13,7 +13,7 @@ android:layout_width="128dp" android:layout_height="128dp" android:layout_centerInParent="true" - android:src="@mipmap/ic_launcher" /> + android:src="@mipmap/app_logo" /> diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java index 98e8df8..02492d7 100644 --- a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java +++ b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java @@ -2,11 +2,15 @@ import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.MapConfigBean; +import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.bean.ToiletListBean; import com.casic.dcms.greendao.MapConfigBeanDao; +import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.greendao.ToiletListBeanDao; import com.casic.dcms.mvvm.model.MapConfigModel; import com.casic.dcms.mvvm.model.ToiletListModel; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; import java.util.ArrayList; import java.util.List; @@ -31,12 +35,66 @@ return instance; } + private final NoticeLocaleBeanDao noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); private final MapConfigBeanDao mapConfigBeanDao = BaseApplication.getDaoSession().getMapConfigBeanDao(); private final ToiletListBeanDao toiletListBeanDao = BaseApplication.getDaoSession().getToiletListBeanDao(); /***路灯本地数据管理************************************************************/ /***通知本地数据管理************************************************************/ + public void savePushNotice(NoticeLocaleBean noticeBean) { + noticeBeanDao.save(noticeBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public int queryUnReadNotice() { + return noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.IsRead.eq("1") + ).list().size(); + } + + public List queryNoticeByPage(String userId, int offset) { + return BaseApplication.getDaoSession() + .queryBuilder(NoticeLocaleBean.class) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) + .limit(LocaleConstant.PAGE_LIMIT) + .list(); + } + + public void deleteNoticeByMessageId(String messageId) { + List result = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list(); + noticeBeanDao.deleteInTx(result); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public void updateNoticeByMessageId(String messageId) { + NoticeLocaleBean noticeLocaleBean = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique(); + noticeLocaleBean.setIsRead("0"); + noticeBeanDao.update(noticeLocaleBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + /***地图本地数据管理************************************************************/ public void deleteAllMapConfig() { diff --git a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java index e7ace6d..90f5796 100644 --- a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java +++ b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java @@ -59,11 +59,10 @@ public static final int CASE_HANDLE = 0; public static final int CASE_VERIFY = 1; public static final int CASE_CHECK = 2; - public static final int PUSH_REGISTER = 11; - public static final int PUSH_MESSAGE_DATA = 12;//透传消息,包含消息的详细数据 - public static final int PUSH_CREATE_NOTIFICATION = 13; - public static final int UPLOAD_LOCATION = 14; - public static final int MESSAGE_NUMBER = 15; + public static final int PUSH_REGISTER = 2022080101; + public static final int UPDATE_NOTICE_FRAGMENT = 2022080102; + public static final int MESSAGE_NUMBER = 2022080103; + public static final int UPDATE_LOCATION = 2022080201; public static final double DEFAULT_LNG = 116.05695247650146; public static final double DEFAULT_LAT = 27.76725390642336; 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..63ef2c4 --- /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/drawable/ic_delete.xml b/app/src/main/res/drawable/ic_delete.xml new file mode 100644 index 0000000..ef661b6 --- /dev/null +++ b/app/src/main/res/drawable/ic_delete.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 8536010..5a8203f 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -13,7 +13,7 @@ android:layout_width="128dp" android:layout_height="128dp" android:layout_centerInParent="true" - android:src="@mipmap/ic_launcher" /> + android:src="@mipmap/app_logo" /> diff --git a/app/src/main/res/layout/fragment_notice.xml b/app/src/main/res/layout/fragment_notice.xml index a11d526..6fa051e 100644 --- a/app/src/main/res/layout/fragment_notice.xml +++ b/app/src/main/res/layout/fragment_notice.xml @@ -1,13 +1,41 @@ - + android:layout_height="match_parent" /> + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e96465..3d99668 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,10 +13,21 @@ + + + + + + + + + + + diff --git a/app/build.gradle b/app/build.gradle index 5206bd0..e260b7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ versionName "v1.0.0.14" manifestPlaceholders = [ - GETUI_APPID: "DR9oeLL9va6aG3DYXy2w39" + GETUI_APPID: "rD5OSy72eI8v86VDdfdrO8" ] } @@ -106,4 +106,6 @@ //经纬度逆编码 implementation 'com.amap.api:search:8.1.0' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34' + //桌面角标 + implementation "me.leolin:ShortcutBadger:1.1.22@aar" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 52d2866..59c2608 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,46 +103,16 @@ - - - - - - - - - - + + + + + + + + + + - + - + @@ -213,4 +181,10 @@ android:name="com.amap.api.v2.apikey" android:value="22b9b1684ea645972d95a627954f4062" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java new file mode 100644 index 0000000..63ffa69 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/adapter/NoticeViewAdapter.java @@ -0,0 +1,114 @@ +package com.casic.dcms.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +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.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.casic.dcms.R; +import com.casic.dcms.bean.NoticeLocaleBean; + +import java.util.List; + +/** + * @author : Pengxh + * @time : 2021/4/15 9:47 + * @email : 290677893@qq.com + **/ +public class NoticeViewAdapter extends RecyclerView.Adapter { + + private static final String TAG = "NoticeViewAdapter"; + private final LayoutInflater layoutInflater; + private final List dataRows; + + public NoticeViewAdapter(Context context, List dataRows) { + this.layoutInflater = LayoutInflater.from(context); + this.dataRows = dataRows; + } + + @Override + public int getItemCount() { + return dataRows.size(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ItemViewHolder(layoutInflater.inflate(R.layout.item_notice_list, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) { + NoticeLocaleBean noticeBean = dataRows.get(position); + holder.dateView.setText(noticeBean.getPushDate()); + holder.titleView.setText(noticeBean.getTitle()); + holder.contentView.setText(noticeBean.getContent()); + if (noticeBean.getIsRead().equals("0")) { + holder.readStateView.setVisibility(View.GONE); + } else { + holder.readStateView.setVisibility(View.VISIBLE); + } + + holder.deleteView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onDeleteClicked(position); + } + }); + + holder.showDetailLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (clickListener == null) { + Log.e(TAG, "onClick: ", new NullPointerException("clickListener == null")); + return; + } + clickListener.onShowMoreClicked(position); + } + }); + } + + static class ItemViewHolder extends RecyclerView.ViewHolder { + + private final TextView dateView; + private final TextView titleView; + private final TextView contentView; + private final TextView readStateView; + private final LinearLayout showDetailLayout; + private final ImageView deleteView; + + ItemViewHolder(@NonNull View itemView) { + super(itemView); + dateView = itemView.findViewById(R.id.dateView); + titleView = itemView.findViewById(R.id.titleView); + contentView = itemView.findViewById(R.id.contentView); + readStateView = itemView.findViewById(R.id.readStateView); + showDetailLayout = itemView.findViewById(R.id.showDetailLayout); + deleteView = itemView.findViewById(R.id.deleteView); + } + } + + private OnItemClickListener clickListener; + + public interface OnItemClickListener { + void onDeleteClicked(int position); + + void onShowMoreClicked(int position); + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.clickListener = onItemClickListener; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java b/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java deleted file mode 100644 index 1a6291a..0000000 --- a/app/src/main/java/com/casic/dcms/adapter/SwipeViewAdapter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.casic.dcms.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.casic.dcms.R; -import com.casic.dcms.bean.NoticeLocaleBean; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeViewHolder; -import com.qmuiteam.qmui.util.QMUIDisplayHelper; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author : Pengxh - * @time : 2021/4/15 9:47 - * @email : 290677893@qq.com - **/ -public class SwipeViewAdapter extends RecyclerView.Adapter { - - private final List mData = new ArrayList<>(); - private final QMUISwipeAction mDeleteAction; - - public SwipeViewAdapter(Context context) { - QMUISwipeAction.ActionBuilder builder = new QMUISwipeAction.ActionBuilder() - .textSize(QMUIDisplayHelper.sp2px(context, 18)) - .textColor(Color.WHITE) - .paddingStartEnd(QMUIDisplayHelper.dp2px(context, 18)); - mDeleteAction = builder.text("删除").backgroundColor(Color.RED).build(); - } - - public void setData(@Nullable List list) { - mData.clear(); - if (list != null) { - mData.addAll(list); - } - notifyDataSetChanged(); - } - - public void remove(int pos) { - mData.remove(pos); - notifyItemRemoved(pos); - } - - @NonNull - @Override - public QMUISwipeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_notice_list, parent, false); - final QMUISwipeViewHolder swipeViewHolder = new QMUISwipeViewHolder(view); - swipeViewHolder.addSwipeAction(mDeleteAction); - return swipeViewHolder; - } - - @Override - public void onBindViewHolder(@NonNull QMUISwipeViewHolder holder, int position) { - TextView noticeTitleView = holder.itemView.findViewById(R.id.noticeTitleView); - TextView noticeDateView = holder.itemView.findViewById(R.id.noticeDateView); - TextView noticeContentView = holder.itemView.findViewById(R.id.noticeContentView); - TextView messageTagView = holder.itemView.findViewById(R.id.messageTagView); - - NoticeLocaleBean noticeBean = mData.get(position); - noticeTitleView.setText(noticeBean.getTitle()); - noticeDateView.setText(noticeBean.getPushDate()); - noticeContentView.setText(noticeBean.getContent()); - if (noticeBean.getIsRead().equals("0")) { - messageTagView.setVisibility(View.GONE); - } else { - messageTagView.setVisibility(View.VISIBLE); - } - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - clickListener.onClick(position); - } - }); - } - - @Override - public int getItemCount() { - return mData.size(); - } - - private OnItemClickListener clickListener; - - public interface OnItemClickListener { - void onClick(int position); - } - - public void setOnItemClickListener(OnItemClickListener onItemClickListener) { - this.clickListener = onItemClickListener; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/base/BaseApplication.java b/app/src/main/java/com/casic/dcms/base/BaseApplication.java index 1a352d3..0974767 100644 --- a/app/src/main/java/com/casic/dcms/base/BaseApplication.java +++ b/app/src/main/java/com/casic/dcms/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.casic.dcms.R; import com.casic.dcms.greendao.DaoMaster; @@ -9,6 +10,7 @@ import com.casic.dcms.utils.FileUtils; import com.casic.dcms.utils.ImageHelper; import com.esri.arcgisruntime.ArcGISRuntimeEnvironment; +import com.igexin.sdk.IUserLoggerInterface; import com.igexin.sdk.PushManager; import com.pengxh.androidx.lite.utils.SaveKeyValues; import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager; @@ -16,6 +18,7 @@ public class BaseApplication extends Application { + private static final String TAG = "BaseApplication"; private static DaoSession daoSession; private volatile static BaseApplication instance; @@ -31,6 +34,12 @@ ArcGISRuntimeEnvironment.setApiKey(getString(R.string.arcgis_key)); //个推初始化 PushManager.getInstance().initialize(this); + PushManager.getInstance().setDebugLogger(this, new IUserLoggerInterface() { + @Override + public void log(String s) { + Log.d(TAG, s); + } + }); initDataBase(); CrashReport.initCrashReport(this, getString(R.string.bugly_app_id), true); } diff --git a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java index b7ef824..bd66cc9 100644 --- a/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java +++ b/app/src/main/java/com/casic/dcms/bean/NoticeLocaleBean.java @@ -3,6 +3,7 @@ import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Unique; /** * @author : Pengxh @@ -17,25 +18,28 @@ @Id(autoincrement = true) private Long id;//主键ID + @Unique + private String messageId; + private String userId; private String userAccount;//登录账户 - private String caseId;//案卷id + private String casePrimaryKey;//案卷主键id private String title;//案卷标题 private String content;//案卷简介 private String pushDate;//推送时间 - private String type;//推送类型 private String isRead;//0-已读;1-未读 - @Generated(hash = 1798907565) - public NoticeLocaleBean(Long id, String userAccount, String caseId, - String title, String content, String pushDate, String type, - String isRead) { + @Generated(hash = 505022675) + public NoticeLocaleBean(Long id, String messageId, String userId, + String userAccount, String casePrimaryKey, String title, String content, + String pushDate, String isRead) { this.id = id; + this.messageId = messageId; + this.userId = userId; this.userAccount = userAccount; - this.caseId = caseId; + this.casePrimaryKey = casePrimaryKey; this.title = title; this.content = content; this.pushDate = pushDate; - this.type = type; this.isRead = isRead; } @@ -51,6 +55,22 @@ this.id = id; } + public String getMessageId() { + return this.messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getUserId() { + return this.userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + public String getUserAccount() { return this.userAccount; } @@ -59,12 +79,12 @@ this.userAccount = userAccount; } - public String getCaseId() { - return this.caseId; + public String getCasePrimaryKey() { + return this.casePrimaryKey; } - public void setCaseId(String caseId) { - this.caseId = caseId; + public void setCasePrimaryKey(String casePrimaryKey) { + this.casePrimaryKey = casePrimaryKey; } public String getTitle() { @@ -91,14 +111,6 @@ this.pushDate = pushDate; } - public String getType() { - return this.type; - } - - public void setType(String type) { - this.type = type; - } - public String getIsRead() { return this.isRead; } diff --git a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java index e8079d7..e5043e3 100644 --- a/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java +++ b/app/src/main/java/com/casic/dcms/greendao/NoticeLocaleBeanDao.java @@ -25,13 +25,14 @@ */ public static class Properties { public final static Property Id = new Property(0, Long.class, "id", true, "_id"); - public final static Property UserAccount = new Property(1, String.class, "userAccount", false, "USER_ACCOUNT"); - public final static Property CaseId = new Property(2, String.class, "caseId", false, "CASE_ID"); - public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); - public final static Property Content = new Property(4, String.class, "content", false, "CONTENT"); - public final static Property PushDate = new Property(5, String.class, "pushDate", false, "PUSH_DATE"); - public final static Property Type = new Property(6, String.class, "type", false, "TYPE"); - public final static Property IsRead = new Property(7, String.class, "isRead", false, "IS_READ"); + public final static Property MessageId = new Property(1, String.class, "messageId", false, "MESSAGE_ID"); + public final static Property UserId = new Property(2, String.class, "userId", false, "USER_ID"); + public final static Property UserAccount = new Property(3, String.class, "userAccount", false, "USER_ACCOUNT"); + public final static Property CasePrimaryKey = new Property(4, String.class, "casePrimaryKey", false, "CASE_PRIMARY_KEY"); + public final static Property Title = new Property(5, String.class, "title", false, "TITLE"); + public final static Property Content = new Property(6, String.class, "content", false, "CONTENT"); + public final static Property PushDate = new Property(7, String.class, "pushDate", false, "PUSH_DATE"); + public final static Property IsRead = new Property(8, String.class, "isRead", false, "IS_READ"); } @@ -48,13 +49,14 @@ String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "\"NOTICE_LOCALE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id - "\"USER_ACCOUNT\" TEXT," + // 1: userAccount - "\"CASE_ID\" TEXT," + // 2: caseId - "\"TITLE\" TEXT," + // 3: title - "\"CONTENT\" TEXT," + // 4: content - "\"PUSH_DATE\" TEXT," + // 5: pushDate - "\"TYPE\" TEXT," + // 6: type - "\"IS_READ\" TEXT);"); // 7: isRead + "\"MESSAGE_ID\" TEXT UNIQUE ," + // 1: messageId + "\"USER_ID\" TEXT," + // 2: userId + "\"USER_ACCOUNT\" TEXT," + // 3: userAccount + "\"CASE_PRIMARY_KEY\" TEXT," + // 4: casePrimaryKey + "\"TITLE\" TEXT," + // 5: title + "\"CONTENT\" TEXT," + // 6: content + "\"PUSH_DATE\" TEXT," + // 7: pushDate + "\"IS_READ\" TEXT);"); // 8: isRead } /** Drops the underlying database table. */ @@ -72,39 +74,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -117,39 +124,44 @@ stmt.bindLong(1, id); } - String userAccount = entity.getUserAccount(); - if (userAccount != null) { - stmt.bindString(2, userAccount); + String messageId = entity.getMessageId(); + if (messageId != null) { + stmt.bindString(2, messageId); } - String caseId = entity.getCaseId(); - if (caseId != null) { - stmt.bindString(3, caseId); + String userId = entity.getUserId(); + if (userId != null) { + stmt.bindString(3, userId); + } + + String userAccount = entity.getUserAccount(); + if (userAccount != null) { + stmt.bindString(4, userAccount); + } + + String casePrimaryKey = entity.getCasePrimaryKey(); + if (casePrimaryKey != null) { + stmt.bindString(5, casePrimaryKey); } String title = entity.getTitle(); if (title != null) { - stmt.bindString(4, title); + stmt.bindString(6, title); } String content = entity.getContent(); if (content != null) { - stmt.bindString(5, content); + stmt.bindString(7, content); } String pushDate = entity.getPushDate(); if (pushDate != null) { - stmt.bindString(6, pushDate); - } - - String type = entity.getType(); - if (type != null) { - stmt.bindString(7, type); + stmt.bindString(8, pushDate); } String isRead = entity.getIsRead(); if (isRead != null) { - stmt.bindString(8, isRead); + stmt.bindString(9, isRead); } } @@ -162,13 +174,14 @@ 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), // userAccount - cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseId - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title - cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // content - cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // pushDate - cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // type - cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // isRead + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // messageId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // userId + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // userAccount + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // casePrimaryKey + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // title + cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // content + cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // pushDate + cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // isRead ); return entity; } @@ -176,13 +189,14 @@ @Override public void readEntity(Cursor cursor, NoticeLocaleBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); - entity.setUserAccount(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); - entity.setCaseId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - entity.setContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); - entity.setPushDate(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); - entity.setType(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); - entity.setIsRead(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setMessageId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); + entity.setUserId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setUserAccount(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setCasePrimaryKey(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setTitle(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + entity.setContent(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); + entity.setPushDate(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); + entity.setIsRead(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); } @Override diff --git a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java b/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java deleted file mode 100644 index 0173fac..0000000 --- a/app/src/main/java/com/casic/dcms/mvvm/model/PushResultBean.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.casic.dcms.mvvm.model; - -public class PushResultBean { - - /** - * content : 您有一个工单超时,请快速处理 - * data : {"id":"1393113365064245250"} - * id : 1393117524798783490 - * title : 工单超时提醒 - * type : alarm - */ - - private String content; - private DataBean data; - private String id;//消息id - private String title; - private String type; - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public DataBean getData() { - return data; - } - - public void setData(DataBean data) { - this.data = data; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public static class DataBean { - /** - * id : 1393113365064245250 - */ - - private String id;//案卷id - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } -} diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java index 1834a99..e5e5baf 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/MainActivity.java @@ -1,10 +1,8 @@ package com.casic.dcms.mvvm.view; -import android.app.Notification; import android.content.Intent; import android.os.Build; import android.os.Handler; -import android.os.Message; import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; @@ -19,10 +17,7 @@ import com.amap.api.location.AMapLocation; import com.casic.dcms.R; import com.casic.dcms.adapter.MainPageAdapter; -import com.casic.dcms.base.BaseApplication; -import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.ActivityMainBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.model.BridgeConfigBean; import com.casic.dcms.mvvm.model.LayerConfigBean; import com.casic.dcms.mvvm.model.MapConfigModel; @@ -35,12 +30,11 @@ import com.casic.dcms.mvvm.vm.PushViewModel; import com.casic.dcms.mvvm.vm.ToiletViewModel; import com.casic.dcms.mvvm.vm.UploadViewModel; -import com.casic.dcms.service.UploadLocationService; +import com.casic.dcms.service.UpdateLocationService; import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.HttpRequestHelper; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.callback.IHttpRequestListener; import com.google.android.material.navigation.NavigationBarView; @@ -62,7 +56,7 @@ public class MainActivity extends AndroidxBaseActivity { private static final String TAG = "MainActivity"; - private static WeakReferenceHandler weakReferenceHandler; + public static WeakReferenceHandler weakReferenceHandler; private DataBaseManager dataBaseManager; private final Gson gson = new Gson(); private final List pageViews = new ArrayList<>(); @@ -102,17 +96,15 @@ //获取配置项 obtainProjectConfig(); - - imei = StringUtil.obtainSimCardSerialNumber(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - startForegroundService(new Intent(this, UploadLocationService.class)); + startForegroundService(new Intent(this, UpdateLocationService.class)); } else { - startService(new Intent(this, UploadLocationService.class)); + startService(new Intent(this, UpdateLocationService.class)); } - updateMessageNumber(); } private void obtainProjectConfig() { + imei = StringUtil.obtainSimCardSerialNumber(this); //地图配置项 mapConfigViewModel.obtainMapConfig(); mapConfigViewModel.mapConfigModel.observe(this, new Observer() { @@ -232,27 +224,10 @@ private final Handler.Callback callback = msg -> { if (msg.what == LocaleConstant.PUSH_REGISTER) { - String clientId = (String) msg.obj; - pushViewModel.registerPush(clientId); - } else if (msg.what == LocaleConstant.PUSH_CREATE_NOTIFICATION) { - //显示小红点 - try { - updateMessageNumber(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createDefault( - noticeBean.getTitle(), - noticeBean.getContent(), - noticeBean.getCaseId(), - CaseDetailActivity.class - ); - notificationHelper.push(1, notification); + pushViewModel.registerPush((String) msg.obj); } else if (msg.what == LocaleConstant.MESSAGE_NUMBER) { updateMessageNumber(); - } else if (msg.what == LocaleConstant.UPLOAD_LOCATION) { + } else if (msg.what == LocaleConstant.UPDATE_LOCATION) { AMapLocation aMapLocation = (AMapLocation) msg.obj; try { double[] gcjToWgs = LocationHelper.gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); @@ -264,39 +239,26 @@ return true; }; + @Override + protected void onResume() { + updateMessageNumber(); + super.onResume(); + } + private void updateMessageNumber() { - List list = BaseApplication.getDaoSession() - .getNoticeLocaleBeanDao() - .queryBuilder() - .where(NoticeLocaleBeanDao.Properties.IsRead.eq("1")) - .list(); - int size = list.size(); - if (size <= 0) { + int unReadNotice = DataBaseManager.getInstance().queryUnReadNotice(); + if (unReadNotice <= 0) { viewBinding.messageNumView.setVisibility(View.GONE); } else { viewBinding.messageNumView.setVisibility(View.VISIBLE); - if (size > 9) { + if (unReadNotice > 9) { viewBinding.messageNumView.setText("9+"); } else { - viewBinding.messageNumView.setText(String.valueOf(size)); + viewBinding.messageNumView.setText(String.valueOf(unReadNotice)); } } } - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); - } - - public static void sendEmptyMessage(int what) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendEmptyMessage(what); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java index e4a3191..94b3b8b 100644 --- a/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java +++ b/app/src/main/java/com/casic/dcms/mvvm/view/fragment/NoticePageFragment.java @@ -1,156 +1,156 @@ package com.casic.dcms.mvvm.view.fragment; -import android.content.Context; -import android.content.Intent; +import android.os.CountDownTimer; import android.os.Handler; import android.os.Message; -import android.text.TextUtils; -import android.util.Log; -import android.view.ViewGroup; +import android.view.View; import androidx.annotation.NonNull; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.casic.dcms.adapter.SwipeViewAdapter; -import com.casic.dcms.base.BaseApplication; +import com.casic.dcms.adapter.NoticeViewAdapter; import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.databinding.FragmentNoticeBinding; -import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.mvvm.view.CaseDetailActivity; -import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; import com.pengxh.androidx.lite.base.AndroidxBaseFragment; -import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction; -import com.qmuiteam.qmui.recyclerView.QMUISwipeAction; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.WeakReferenceHandler; +import com.scwang.smartrefresh.layout.api.RefreshLayout; +import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -//TODO 后续调整,参考闸井产品 public class NoticePageFragment extends AndroidxBaseFragment { private static final String TAG = "NoticePageFragment"; - private static WeakReferenceHandler weakReferenceHandler; - private Context context; - private NoticeLocaleBeanDao noticeBeanDao; - private SwipeViewAdapter swipeViewAdapter; - private List noticeBeans = new ArrayList<>(); + public static WeakReferenceHandler weakReferenceHandler; + private NoticeViewAdapter noticeViewAdapter; + private List dataBeans = new ArrayList<>(); + private int pageIndex = 0; // 本地数据库分页从0开始 + private boolean isRefresh = false; + private boolean isLoadMore = false; @Override protected void setupTopBarLayout() { - context = getContext(); + } @Override protected void initData() { - swipeViewAdapter = new SwipeViewAdapter(context); - //根据loginName加载历史数据 - String account = StringHelper.getUserBean().getAccount(); - if (TextUtils.isEmpty(account)) { - return; - } - noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); - noticeBeans = noticeBeanDao.queryBuilder() - .where(NoticeLocaleBeanDao.Properties.UserAccount.eq(account)) - .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) //按时间顺序最新顺序排序 - .list(); - swipeViewAdapter.setData(noticeBeans); - weakReferenceHandler = new WeakReferenceHandler(this); + weakReferenceHandler = new WeakReferenceHandler(callback); } @Override - protected void initEvent() { - QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() { - @Override - public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = viewHolder.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - - @Override - public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - return QMUIRVItemSwipeAction.SWIPE_LEFT; - } - - @Override - public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) { - super.onClickAction(swipeAction, selected, action); - //更新小红点 - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - int position = selected.getAdapterPosition(); - noticeBeanDao.delete(noticeBeans.get(position)); - swipeViewAdapter.remove(position); - } - }); - swipeAction.attachToRecyclerView(viewBinding.swipeRecyclerView); - LinearLayoutManager layoutManager = new LinearLayoutManager(context) { - @Override - public RecyclerView.LayoutParams generateDefaultLayoutParams() { - return new RecyclerView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ); - } - }; - viewBinding.swipeRecyclerView.setLayoutManager(layoutManager); - viewBinding.swipeRecyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); - viewBinding.swipeRecyclerView.setAdapter(swipeViewAdapter); - swipeViewAdapter.setOnItemClickListener(new SwipeViewAdapter.OnItemClickListener() { - @Override - public void onClick(int position) { - MainActivity.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); - - //点击之后之后,未读消息变为已读消息 - NoticeLocaleBean noticeBean = noticeBeans.get(position); - noticeBean.setIsRead("0"); - noticeBeanDao.update(noticeBean); - swipeViewAdapter.notifyDataSetChanged(); - String caseId = noticeBeans.get(position).getCaseId(); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); - } - }); + public void onResume() { + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + super.onResume(); } - private static class WeakReferenceHandler extends Handler { - private final WeakReference reference; - - private WeakReferenceHandler(NoticePageFragment fragment) { - reference = new WeakReference<>(fragment); - } - + private final Handler.Callback callback = new Handler.Callback() { @Override - public void handleMessage(Message msg) { - NoticePageFragment noticePageFragment; - try { - noticePageFragment = reference.get(); - List noticeBeans = noticePageFragment.noticeBeans; - if (msg.what == LocaleConstant.PUSH_MESSAGE_DATA) { - NoticeLocaleBean noticeBean = (NoticeLocaleBean) msg.obj; - Log.d(TAG, "收到推送消息,更新列表: " + noticeBean.getCaseId()); - noticeBeans.add(0, noticeBean); //新消息永远放到第一个 - //更新数据 - noticePageFragment.swipeViewAdapter.setData(noticeBeans); + public boolean handleMessage(@NonNull Message msg) { + if (msg.what == LocaleConstant.UPDATE_NOTICE_FRAGMENT) { + if (isRefresh || isLoadMore) { + noticeViewAdapter.notifyDataSetChanged(); + } else { + if (dataBeans.size() == 0) { + viewBinding.emptyView.show(false, "没有任何通知", null, "刷新", new View.OnClickListener() { + @Override + public void onClick(View v) { + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }); + } else { + viewBinding.emptyView.hide(); + noticeViewAdapter = new NoticeViewAdapter(requireContext(), dataBeans); + viewBinding.noticeRecyclerView.setAdapter(noticeViewAdapter); + noticeViewAdapter.setOnItemClickListener(new NoticeViewAdapter.OnItemClickListener() { + @Override + public void onDeleteClicked(int position) { + DataBaseManager.getInstance().deleteNoticeByMessageId(dataBeans.get(position).getMessageId()); + dataBeans.remove(position); + noticeViewAdapter.notifyItemRemoved(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + + @Override + public void onShowMoreClicked(int position) { + String caseId = dataBeans.get(position).getCasePrimaryKey(); + ContextUtil.navigatePageTo(requireContext(), CaseDetailActivity.class, caseId); + //更改数据库里通知状态 + DataBaseManager.getInstance().updateNoticeByMessageId(dataBeans.get(position).getMessageId()); + noticeViewAdapter.notifyItemChanged(position); + noticeViewAdapter.notifyItemRangeChanged( + position, dataBeans.size() - position + ); + } + }); + } } - } catch (NullPointerException e) { - e.printStackTrace(); } + return true; } + }; - } + @Override + protected void initEvent() { + viewBinding.noticeLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + isRefresh = true; + new CountDownTimer(1000, 500) { - public static void sendMessage(Message msg) { - if (weakReferenceHandler == null) { - return; - } - weakReferenceHandler.sendMessage(msg); + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isRefresh = false; + dataBeans.clear(); + pageIndex = 0; + dataBeans = DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex); + + refreshLayout.finishRefresh(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); + + viewBinding.noticeLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + isLoadMore = true; + new CountDownTimer(1000, 500) { + + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + isLoadMore = false; + pageIndex++; + dataBeans.addAll( + DataBaseManager.getInstance().queryNoticeByPage(StringHelper.getUserBean().getId(), pageIndex) + ); + refreshLayout.finishLoadMore(); + weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + } + }.start(); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java index 18b9cdd..839a349 100644 --- a/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java +++ b/app/src/main/java/com/casic/dcms/service/GeTuiIntentService.java @@ -1,26 +1,21 @@ package com.casic.dcms.service; import android.content.Context; -import android.content.Intent; import android.os.Message; -import android.text.TextUtils; import android.util.Log; -import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.NoticeLocaleBean; -import com.casic.dcms.mvvm.model.PushResultBean; import com.casic.dcms.mvvm.view.CaseDetailActivity; import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; +import com.casic.dcms.utils.DataBaseManager; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.StringHelper; -import com.casic.dcms.utils.TimeOrDateUtil; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.igexin.sdk.GTIntentService; import com.igexin.sdk.message.GTCmdMessage; import com.igexin.sdk.message.GTNotificationMessage; import com.igexin.sdk.message.GTTransmitMessage; +import com.pengxh.androidx.lite.utils.ContextUtil; +import com.pengxh.androidx.lite.utils.TimeOrDateUtil; /** * @author : Pengxh @@ -39,56 +34,19 @@ // 处理透传消息 @Override public void onReceiveMessageData(Context context, GTTransmitMessage msg) { - /** - * appid = DR9oeLL9va6aG3DYXy2w39 - * taskid = TEST_0515_d4689edeff9808959f10365895682f6f - * messageid = bd9c2465afd5464fb99368a579fd3fc8 - * pkg = com.casic.dcms - * cid = 9e85018b1972d664d9e86e9a6d03b4a7 - * playload = {"content":"您有一个工单超时,请快速处理1","data":{"id":"1392655327805825025"},"id":1393472265320001538,"title":"工单超时提醒","type":"NORMAL"} - */ - Gson gson = new Gson(); - String messageContent = new String(msg.getPayload()); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - NoticeLocaleBean noticeBean = new NoticeLocaleBean(); - noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); - noticeBean.setCaseId(resultBean.getData().getId()); - noticeBean.setTitle(resultBean.getTitle()); - noticeBean.setContent(resultBean.getContent()); - noticeBean.setType(resultBean.getType()); - noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); - noticeBean.setIsRead("1"); - //存本地一份 - BaseApplication.getDaoSession().getNoticeLocaleBeanDao().insert(noticeBean); - - //创建通知栏 - Message msgNotice = Message.obtain(); - msgNotice.what = LocaleConstant.PUSH_CREATE_NOTIFICATION; - msgNotice.obj = noticeBean; - MainActivity.sendMessage(msgNotice); - - //发送消息更新界面 - Message msgBean = Message.obtain(); - msgBean.what = LocaleConstant.PUSH_MESSAGE_DATA; - msgBean.obj = noticeBean; - NoticePageFragment.sendMessage(msgBean); } // 接收 cid @Override public void onReceiveClientId(Context context, String clientid) { - Log.d(TAG, "onReceiveClientId -> clientid = $clientid"); + //51ea9bde792e0697e1b3b6d7b48b6600 + Log.d(TAG, "onReceiveClientId -> " + clientid); //通知MainActivity注册个推服务 - if (!TextUtils.isEmpty(clientid)) { - Message msg = Message.obtain(); - msg.what = LocaleConstant.PUSH_REGISTER; - msg.obj = clientid; - MainActivity.sendMessage(msg); - } else { - Log.d(TAG, "onReceiveClientId: ===>clientid = $clientid"); - } + Message msg = MainActivity.weakReferenceHandler.obtainMessage(); + msg.what = LocaleConstant.PUSH_REGISTER; + msg.obj = clientid; + MainActivity.weakReferenceHandler.sendMessage(msg); } // cid 离线上线通知 @@ -105,21 +63,42 @@ // 通知到达,只有个推通道下发的通知会回调此方法 @Override - public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) { - Log.d(TAG, "onNotificationMessageArrived: 通知到达"); + public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { + /** + * { + * "content": "工单1486662451409330177超时,请快速处理", + * "messageId": "15c1673cda4542f79c746d4dbfd9163b", + * "taskId": "TEST_0802_2ad46ce35d8b3bd9d8396de090ff6fc4", + * "title": "工单超时提醒", + * "appid": "rD5OSy72eI8v86VDdfdrO8", + * "clientId": "51ea9bde792e0697e1b3b6d7b48b6600", + * "pkgName": "com.casic.dcms" + * } + * */ + if (msg == null) { + return; + } + NoticeLocaleBean noticeBean = new NoticeLocaleBean(); + noticeBean.setMessageId(msg.getMessageId()); + noticeBean.setUserId(StringHelper.getUserBean().getId()); + noticeBean.setUserAccount(StringHelper.getUserBean().getAccount()); + String msgContent = msg.getContent(); + String caseId = msgContent.substring(2, 21); + noticeBean.setCasePrimaryKey(caseId); + noticeBean.setTitle(msg.getTitle()); + noticeBean.setContent(msgContent); + noticeBean.setPushDate(TimeOrDateUtil.timestampToCompleteDate(System.currentTimeMillis())); + noticeBean.setIsRead("1"); + //存本地一份 + DataBaseManager.getInstance().savePushNotice(noticeBean); } // 通知点击,只有个推通道下发的通知会回调此方法 @Override public void onNotificationMessageClicked(Context context, GTNotificationMessage message) { - Gson gson = new Gson(); String messageContent = message.getContent(); - PushResultBean resultBean = gson.fromJson(messageContent, new TypeToken() { - }.getType()); - String caseId = resultBean.getData().getId(); - Log.d(TAG, "onNotificationMessageClicked: " + caseId); - Intent intent = new Intent(context, CaseDetailActivity.class); - intent.putExtra("id", caseId); - startActivity(intent); + String msgContent = message.getContent(); + String caseId = msgContent.substring(2, 21); + ContextUtil.navigatePageTo(context, CaseDetailActivity.class, caseId); } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java new file mode 100644 index 0000000..f4a0772 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/service/UpdateLocationService.java @@ -0,0 +1,52 @@ +package com.casic.dcms.service; + +import android.app.Notification; +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.Message; +import android.util.Log; + +import androidx.annotation.Nullable; + +import com.amap.api.location.AMapLocation; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.utils.LocaleConstant; +import com.casic.dcms.utils.LocationHelper; +import com.casic.dcms.utils.NotificationHelper; +import com.casic.dcms.utils.callback.ILocationListener; + +public class UpdateLocationService extends Service { + + private static final String TAG = "UploadLocationService"; + + @Override + public void onCreate() { + super.onCreate(); + NotificationHelper notificationHelper = NotificationHelper.getInstance(this); + Notification notification = notificationHelper.createKeepAlive(); + startForeground(Integer.MAX_VALUE, notification); + LocationHelper.obtainCurrentLocation(this, new ILocationListener() { + + @Override + public void onAMapLocationGet(AMapLocation aMapLocation) { + Message message = MainActivity.weakReferenceHandler.obtainMessage(); + message.what = LocaleConstant.UPDATE_LOCATION; + message.obj = aMapLocation; + MainActivity.weakReferenceHandler.sendMessage(message); + } + }, false); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + // 如果Service被终止,当资源允许情况下,重启service + return START_STICKY; + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java b/app/src/main/java/com/casic/dcms/service/UploadLocationService.java deleted file mode 100644 index a3949a4..0000000 --- a/app/src/main/java/com/casic/dcms/service/UploadLocationService.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.casic.dcms.service; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.os.Message; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.amap.api.location.AMapLocation; -import com.casic.dcms.mvvm.view.MainActivity; -import com.casic.dcms.utils.LocaleConstant; -import com.casic.dcms.utils.LocationHelper; -import com.casic.dcms.utils.NotificationHelper; -import com.casic.dcms.utils.callback.ILocationListener; - -public class UploadLocationService extends Service { - - private static final String TAG = "UploadLocationService"; - - @Override - public void onCreate() { - super.onCreate(); - NotificationHelper notificationHelper = NotificationHelper.getInstance(this); - Notification notification = notificationHelper.createKeepAlive(); - startForeground(Integer.MAX_VALUE, notification); - LocationHelper.obtainCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - Log.d(TAG, "onAMapLocationGet: UploadLocationService"); - Message message = Message.obtain(); - message.what = LocaleConstant.UPLOAD_LOCATION; - message.obj = aMapLocation; - MainActivity.sendMessage(message); - } - }, false); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - // 如果Service被终止,当资源允许情况下,重启service - return START_STICKY; - } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/casic/dcms/utils/BadeHelper.java b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java new file mode 100644 index 0000000..1121b01 --- /dev/null +++ b/app/src/main/java/com/casic/dcms/utils/BadeHelper.java @@ -0,0 +1,15 @@ +package com.casic.dcms.utils; + +import android.content.Context; + +import me.leolin.shortcutbadger.ShortcutBadger; + +public class BadeHelper { + public static void setBadgeNum(Context context, int badgeCount) { + if (badgeCount == 0) { + ShortcutBadger.removeCount(context); + } else { + ShortcutBadger.applyCount(context, badgeCount); + } + } +} diff --git a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java index 98e8df8..02492d7 100644 --- a/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java +++ b/app/src/main/java/com/casic/dcms/utils/DataBaseManager.java @@ -2,11 +2,15 @@ import com.casic.dcms.base.BaseApplication; import com.casic.dcms.bean.MapConfigBean; +import com.casic.dcms.bean.NoticeLocaleBean; import com.casic.dcms.bean.ToiletListBean; import com.casic.dcms.greendao.MapConfigBeanDao; +import com.casic.dcms.greendao.NoticeLocaleBeanDao; import com.casic.dcms.greendao.ToiletListBeanDao; import com.casic.dcms.mvvm.model.MapConfigModel; import com.casic.dcms.mvvm.model.ToiletListModel; +import com.casic.dcms.mvvm.view.MainActivity; +import com.casic.dcms.mvvm.view.fragment.NoticePageFragment; import java.util.ArrayList; import java.util.List; @@ -31,12 +35,66 @@ return instance; } + private final NoticeLocaleBeanDao noticeBeanDao = BaseApplication.getDaoSession().getNoticeLocaleBeanDao(); private final MapConfigBeanDao mapConfigBeanDao = BaseApplication.getDaoSession().getMapConfigBeanDao(); private final ToiletListBeanDao toiletListBeanDao = BaseApplication.getDaoSession().getToiletListBeanDao(); /***路灯本地数据管理************************************************************/ /***通知本地数据管理************************************************************/ + public void savePushNotice(NoticeLocaleBean noticeBean) { + noticeBeanDao.save(noticeBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public int queryUnReadNotice() { + return noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.IsRead.eq("1") + ).list().size(); + } + + public List queryNoticeByPage(String userId, int offset) { + return BaseApplication.getDaoSession() + .queryBuilder(NoticeLocaleBean.class) + .where(NoticeLocaleBeanDao.Properties.UserId.eq(userId)) + .offset(offset * LocaleConstant.PAGE_LIMIT) + .orderDesc(NoticeLocaleBeanDao.Properties.PushDate) + .limit(LocaleConstant.PAGE_LIMIT) + .list(); + } + + public void deleteNoticeByMessageId(String messageId) { + List result = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).list(); + noticeBeanDao.deleteInTx(result); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + + public void updateNoticeByMessageId(String messageId) { + NoticeLocaleBean noticeLocaleBean = noticeBeanDao.queryBuilder().where( + NoticeLocaleBeanDao.Properties.MessageId.eq(messageId) + ).unique(); + noticeLocaleBean.setIsRead("0"); + noticeBeanDao.update(noticeLocaleBean); + //角标设置 + BadeHelper.setBadgeNum(BaseApplication.getInstance(), queryUnReadNotice()); + //更新消息界面 + NoticePageFragment.weakReferenceHandler.sendEmptyMessage(LocaleConstant.UPDATE_NOTICE_FRAGMENT); + //更新底部导航消息数量 + MainActivity.weakReferenceHandler.sendEmptyMessage(LocaleConstant.MESSAGE_NUMBER); + } + /***地图本地数据管理************************************************************/ public void deleteAllMapConfig() { diff --git a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java index e7ace6d..90f5796 100644 --- a/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java +++ b/app/src/main/java/com/casic/dcms/utils/LocaleConstant.java @@ -59,11 +59,10 @@ public static final int CASE_HANDLE = 0; public static final int CASE_VERIFY = 1; public static final int CASE_CHECK = 2; - public static final int PUSH_REGISTER = 11; - public static final int PUSH_MESSAGE_DATA = 12;//透传消息,包含消息的详细数据 - public static final int PUSH_CREATE_NOTIFICATION = 13; - public static final int UPLOAD_LOCATION = 14; - public static final int MESSAGE_NUMBER = 15; + public static final int PUSH_REGISTER = 2022080101; + public static final int UPDATE_NOTICE_FRAGMENT = 2022080102; + public static final int MESSAGE_NUMBER = 2022080103; + public static final int UPDATE_LOCATION = 2022080201; public static final double DEFAULT_LNG = 116.05695247650146; public static final double DEFAULT_LAT = 27.76725390642336; 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..63ef2c4 --- /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/drawable/ic_delete.xml b/app/src/main/res/drawable/ic_delete.xml new file mode 100644 index 0000000..ef661b6 --- /dev/null +++ b/app/src/main/res/drawable/ic_delete.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 8536010..5a8203f 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -13,7 +13,7 @@ android:layout_width="128dp" android:layout_height="128dp" android:layout_centerInParent="true" - android:src="@mipmap/ic_launcher" /> + android:src="@mipmap/app_logo" /> diff --git a/app/src/main/res/layout/fragment_notice.xml b/app/src/main/res/layout/fragment_notice.xml index a11d526..6fa051e 100644 --- a/app/src/main/res/layout/fragment_notice.xml +++ b/app/src/main/res/layout/fragment_notice.xml @@ -1,13 +1,41 @@ - + android:layout_height="match_parent" /> + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_notice_list.xml b/app/src/main/res/layout/item_notice_list.xml index c2a4029..c54568c 100644 --- a/app/src/main/res/layout/item_notice_list.xml +++ b/app/src/main/res/layout/item_notice_list.xml @@ -2,61 +2,97 @@ + android:paddingHorizontal="@dimen/dp_10"> - - - - - - - - + android:gravity="center" + android:paddingVertical="@dimen/dp_5" + android:text="2022/07/04 15:05:45" + android:textColor="@color/subTextColor" /> + + + + + + + + + + + + android:gravity="center" + android:paddingHorizontal="@dimen/dp_7" + android:paddingTop="@dimen/dp_10" + android:paddingBottom="@dimen/dp_5" + android:text="设备编号412019010211发生井盖开盖报警" + android:textColor="@color/mainTextColor" + android:textSize="@dimen/sp_16" /> - - + + + + + + + + + + + \ No newline at end of file