wjc
74 分钟以前 8b43d4e1190fc9e2261be0579e53cc6c2987f946
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package com.hdl.photovoltaic.ui.me;
 
 
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
 
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.linkpm.sdk.user.bean.NewVersionBean;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.base.CustomBaseActivity;
import com.hdl.photovoltaic.config.AppConfigManage;
import com.hdl.photovoltaic.databinding.ActivityAsRegardsBinding;
import com.hdl.photovoltaic.enums.ShowErrorMode;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.other.HdlAppUpdateLogic;
import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.ui.BPowerStationActivity;
import com.hdl.photovoltaic.ui.CPowerStationActivity;
import com.hdl.photovoltaic.ui.StartActivity;
import com.hdl.photovoltaic.utils.BadgeUtils;
import com.hdl.photovoltaic.widget.FlashingBoxDialog;
import com.hdl.photovoltaic.widget.apkwgtupload.ApkDownLoadService;
import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
import com.hdl.photovoltaic.widget.UpdateConfirmationCancelDialog;
 
import java.util.Map;
 
/**
 * 关于界面(app更新)
 */
public class AsRegardsActivity extends CustomBaseActivity {
 
    /**
     * 版本更新对象
     */
    private NewVersionBean mNewVersionBean = null;
 
    public ActivityAsRegardsBinding viewBinding;
 
    @Override
    public Object getContentView() {
        viewBinding = ActivityAsRegardsBinding.inflate(getLayoutInflater());
        return viewBinding.getRoot();
    }
 
    @Override
    public void onBindView(Bundle savedInstanceState) {
        setStatusBarTranslucent();
        getWindow().setNavigationBarColor(getColor(R.color.text_FF000000));
        //初始化
        initView();
        //初始化界面监听器
        initEvent();
        //读取数据
        readData();
    }
 
    private void readData() {
        HdlAppUpdateLogic.getInstance().checkAppVersion(AppConfigManage.getVersionName(), new CloudCallBeak<NewVersionBean>() {
            @Override
            public void onSuccess(NewVersionBean newVersionBean) {
                //初始化对象
                mNewVersionBean = newVersionBean;
                if (newVersionBean != null) {
                    //todo 发现新版本,改变UI样式
                    viewBinding.asRegardsRlRightContentTv.setText(R.string.app_discover_new_version);
                    viewBinding.asRegardsRlRightContentTv.setTextColor(getResources().getColor(R.color.text_FFACACAC, null));
                }
            }
 
            @Override
            public void onFailure(HDLException e) {
 
            }
        });
        //正式环境
        String content = "https://developer.hdlcontrol.com/AppDownload/HDLPhotovoltaicDownload.html";
        if (!AppConfigManage.getOnlineServer()) {
            //测试环境
            content = "https://developer.hdlcontrol.com/AppDownload/HDLPhotovoltaicDebugDownload.html";
        }
        Bitmap bitmap = HdlCommonLogic.getInstance().createQRCodeBitmap(content, 168, 168, "UTF-8", "H", "0", getColor(R.color.text_00000000), Color.WHITE);
        viewBinding.asRegardsQrCodeIv.setImageBitmap(bitmap);
 
    }
 
 
    private void initEvent() {
        viewBinding.toolbarTopRl.topBackLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
 
        viewBinding.asRegardsVersionUpdatingRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateTipDialog();
            }
        });
 
        viewBinding.serviceAgreementRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("type", WebActivity.ServiceAgreement);
                intent.setClass(_mActivity, WebActivity.class);
                startActivity(intent);
            }
 
        });
        viewBinding.privacyPolicyRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("type", WebActivity.PrivacyAgreement);
                intent.setClass(_mActivity, WebActivity.class);
                startActivity(intent);
 
            }
        });
        viewBinding.contactUsRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(_mActivity, ContactUsActivity.class);
                startActivity(intent);
                String json = "{\"expandData\":{\"expantContent\":\"{\\\"createTime\\\":1763705189605,\\\"homeName\\\":\\\"智能模式测试\\\",\\\"isRead\\\":false,\\\"msgId\\\":1991742202645020673,\\\"type\\\":\\\"EVENT\\\",\\\"homeId\\\":1990254883420880898,\\\"status\\\":\\\"UNTREATED\\\"}\",\"homeId\":1990254883420880898,\"messageType\":\"Alarm\"},\"aps\":{\"badge\":2,\"alert\":{\"title\":\"event\",\"body\":\"Battery voltage low\"}}}";
////                Gson gson = new Gson();
////                Type type = new TypeToken<Map<String, String>>() {
////                }.getType();
////                Map<String, String> map = gson.fromJson(json, type);
//                Map<String, String> map = JSONObject.parseObject(json, new TypeReference<Map<String, String>>() {
//                });
//                showCustomNotification("模拟标题", "模拟数据", map);
////                HdlPushLogic.getInstance().pushDataProcessing("", "", json);
            }
        });
 
    }
 
    private void initView() {
        viewBinding.toolbarTopRl.topBarView.setBackgroundColor(getColor(R.color.text_00000000));
        viewBinding.toolbarTopRl.topTitleTv.setText(R.string.me_regard);
        viewBinding.toolbarTopRl.topBackLl.setVisibility(View.VISIBLE);
        String versionsStr = _mActivity.getResources().getString(R.string.app_version_number) + " " + AppConfigManage.getVersionName();
        viewBinding.asRegardsIconVersionsTv.setText(versionsStr);
 
    }
 
    /**
     * App新版本提示框
     */
    private void updateTipDialog() {
        HdlThreadLogic.runMainThread(new Runnable() {
            @Override
            public void run() {
                if (mNewVersionBean == null) {
                    FlashingBoxDialog flashingBoxDialog = new FlashingBoxDialog(_mActivity, 1500);
                    flashingBoxDialog.setContent(getString(R.string.app_new_version));
                    flashingBoxDialog.show();
                    return;
                }
                String app_version = getString(R.string.app_version) + ":" + mNewVersionBean.getVersion();
                int kb = (int) (mNewVersionBean.getSize() / 1024);
                String mb = (kb / 1024) + "." + ((kb % 1024) + "").charAt(0) + "MB";//mb保留一位
                String app_package_size = getString(R.string.app_package_size) + ":" + mb;
                String content1 = app_version + "\n" + app_package_size;
                String content2 = mNewVersionBean.getRemark();
                UpdateConfirmationCancelDialog updateConfirmationCancelDialog = new UpdateConfirmationCancelDialog(_mActivity);
                updateConfirmationCancelDialog.setContent1(content1);
                updateConfirmationCancelDialog.setContent2(content2);
                updateConfirmationCancelDialog.show();
                updateConfirmationCancelDialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() {
                    @Override
                    public void Confirm() {
                        Intent intent = new Intent(_mActivity, ApkDownLoadService.class);
                        intent.putExtra("updateUrl", mNewVersionBean.getPackageUrl());
                        intent.putExtra("downLoadName", HdlAppUpdateLogic.getInstance().getApkFileName());
                        intent.putExtra("downLoadType", "0");
                        _mActivity.startService(intent);
                        updateConfirmationCancelDialog.dismiss();
 
                    }
                });
 
                updateConfirmationCancelDialog.setNoOnclickListener(new ConfirmationCancelDialog.onNoOnclickListener() {
                    @Override
                    public void Cancel() {
                        updateConfirmationCancelDialog.dismiss();
                    }
                });
            }
        }, this, ShowErrorMode.YES);
    }
 
    private void showCustomNotification(String title, String message, Map<String, String> data) {
        NotificationManager notificationManager =
                (NotificationManager) _mActivity.getSystemService(Context.NOTIFICATION_SERVICE);
 
        // 创建通知渠道(Android 8.0+)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            createNotificationChannel(notificationManager);
        }
 
        NotificationCompat.Builder builder = new NotificationCompat.Builder(_mActivity, "fcm_channel")
                .setSmallIcon(R.drawable.notification_logo)
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setNumber(5)
                .setWhen(System.currentTimeMillis());
 
 
        // 设置点击意图
        Intent intent = createNotificationIntent(data);
        PendingIntent pendingIntent = PendingIntent.getActivity(
                _mActivity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
        builder.setContentIntent(pendingIntent);
 
        // 显示通知
        notificationManager.notify((int) System.currentTimeMillis(), builder.build());
    }
 
    private Intent createNotificationIntent(Map<String, String> data) {
        Intent intent = new Intent(_mActivity, StartActivity.class);
        intent.putExtra("from_fcm", true);
        intent.putExtra("pushData", JSON.toJSON(data).toString());
//        if (data != null) {
//            for (Map.Entry<String, String> entry : data.entrySet()) {
//                intent.putExtra(entry.getKey(), entry.getValue());
//            }
//        }
 
//        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        return intent;
    }
 
    @RequiresApi(api = Build.VERSION_CODES.O)
    private void createNotificationChannel(NotificationManager notificationManager) {
        NotificationChannel channel = new NotificationChannel(
                "fcm_channel",
                "FCM 消息",
                NotificationManager.IMPORTANCE_HIGH
        );
        channel.setDescription("Firebase Cloud Messaging 通知");
        // 启用角标
        channel.setShowBadge(true);
        notificationManager.createNotificationChannel(channel);
        BadgeUtils.setBadgeCount(_mActivity, 7);
    }
}