正在查看: WeatherSense v1.8.9 应用的 HistroyDataService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: WeatherSense v1.8.9 应用的 HistroyDataService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.emax.weather.service;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import com.emax.weahter.R;
import com.emax.weather.bean.DeviceWeather;
import com.emax.weather.bean.HistoryResult;
import com.emax.weather.bean.Page;
import com.emax.weather.bean.db.DaoHadle;
import com.emax.weather.net.ApiException;
import com.emax.weather.net.CodeHandledSubscriber;
import com.emax.weather.net.ResponseData;
import com.emax.weather.net.RetrofitUtil;
import com.emax.weather.receiver.DataDownloadReceiver;
import com.emax.weather.service.HistroyDataService;
import com.ezon.health.utils_lib.SharedPre;
import com.ezon.health.utils_lib.SharedPreUtils;
import com.ezon.health.utils_lib.TimeUtils;
import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class HistroyDataService extends Service {
private Disposable disposable;
private long historyNum;
private Page pageResult;
static long access$014(HistroyDataService histroyDataService, long j) {
long j2 = histroyDataService.historyNum + j;
histroyDataService.historyNum = j2;
return j2;
}
public static void startService(Context context) {
Intent intent = new Intent(context, (Class<?>) HistroyDataService.class);
try {
if (Build.VERSION.SDK_INT >= 26) {
context.startForegroundService(intent);
System.out.println("lyq climate 启动HistroyDataService 11");
} else {
context.startService(intent);
System.out.println("lyq climate 启动HistroyDataService 22");
}
} catch (Exception e) {
System.out.println("lyq climate 启动HistroyDataService exception");
System.out.println("历史数据服务启动失败");
e.printStackTrace();
}
}
public static void stopService(Context context) {
System.out.println("lyq climate 停止 HistroyDataService");
context.stopService(new Intent(context, (Class<?>) HistroyDataService.class));
}
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= 26) {
Notification.Builder when = new Notification.Builder(getApplicationContext()).setSmallIcon(R.drawable.app_logo).setContentTitle(getResources().getString(2131755129)).setContentText(getResources().getString(R.string.download_data)).setWhen(System.currentTimeMillis());
NotificationChannel notificationChannel = new NotificationChannel("channel_id", "history", 1);
notificationChannel.enableLights(false);
notificationChannel.setShowBadge(false);
notificationChannel.setLockscreenVisibility(-1);
((NotificationManager) getSystemService("notification")).createNotificationChannel(notificationChannel);
when.setChannelId("channel_id");
Notification build = when.build();
build.defaults = 1;
if (Build.VERSION.SDK_INT >= 33) {
startForeground(1, build, 1);
} else {
startForeground(1, build);
}
System.out.println("lyq climate HistroyDataService onCreate 创建正在下载的通知");
}
initPage();
}
private void initPage() {
this.historyNum = DaoHadle.getHistoryWeatherListSize();
Page page = new Page();
this.pageResult = page;
page.setSize(50);
this.pageResult.setNumber(0);
this.pageResult.setEndTime(System.currentTimeMillis() / 1000);
this.pageResult.setSortDirection("ASC");
if (SharedPreUtils.getInt(getApplicationContext(), SharedPre.DbVersion.DB_VERSION, 0) == 0) {
SharedPreUtils.putLong(getApplicationContext(), SharedPre.User.LAST_UPDATE_HISTORY_TIME, 0L);
DaoHadle.deleteHistoryData();
SharedPreUtils.putInt(getApplicationContext(), SharedPre.DbVersion.DB_VERSION, 1);
}
long j = SharedPreUtils.getLong(getApplicationContext(), SharedPre.User.LAST_UPDATE_HISTORY_TIME, 0L);
if (j != 0) {
System.out.println("lyq climate initPage 上次下载的时间:" + j);
this.pageResult.setStartTime(j);
return;
}
this.pageResult.setStartTime(0L);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
getHistory();
return super.onStartCommand(intent, flags, startId);
}
public void getHistory() {
HashMap hashMap = new HashMap();
hashMap.put("size", String.valueOf(this.pageResult.getSize()));
hashMap.put("page", String.valueOf(this.pageResult.getNumber()));
hashMap.put("startTime", String.valueOf(this.pageResult.getStartTime()));
hashMap.put("endTime", String.valueOf(this.pageResult.getEndTime()));
hashMap.put("sortDirection", String.valueOf(this.pageResult.getSortDirection()));
long startTime = this.pageResult.getStartTime();
long endTime = this.pageResult.getEndTime();
System.out.println("lyq climate 获取历史数据 -------> 开始时间:" + TimeUtils.millis2String(startTime * 1000, "yyyy-MM-dd HH:mm:ss") + ",结束时间: " + TimeUtils.millis2String(endTime * 1000, "yyyy-MM-dd HH:mm:ss") + ",number:" + this.pageResult.getNumber());
requestHistory(hashMap);
}
public static boolean checkNetworkAvailable(Context context) {
NetworkInfo[] allNetworkInfo;
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
if (connectivityManager != null && (allNetworkInfo = connectivityManager.getAllNetworkInfo()) != null) {
for (int i = 0; i < allNetworkInfo.length; i++) {
if (allNetworkInfo[i].getState() == NetworkInfo.State.CONNECTED) {
NetworkInfo networkInfo = allNetworkInfo[i];
if (networkInfo.getType() == 1 || networkInfo.getType() == 0) {
return true;
}
}
}
}
return false;
}
public void requestHistory(Map<String, String> map) {
if (DaoHadle.getUser() != null) {
System.out.println("lyq 获取历史数据 start ----");
RetrofitUtil.getHttpService().getHistoryData(DaoHadle.getUser().getToken(), map).compose(new RetrofitUtil.CommonOptions()).timeout(10L, TimeUnit.SECONDS).observeOn(Schedulers.newThread()).subscribe(new AnonymousClass1(this));
}
}
class AnonymousClass1 extends CodeHandledSubscriber<ResponseData<HistoryResult>> {
AnonymousClass1(Context context) {
super(context);
}
@Override
protected void onError(ApiException apiException) {
System.out.println("lyq 获取历史数据 请求失败" + apiException.getDisplayMessage() + " 继续请求数据");
Observable.timer(15L, TimeUnit.SECONDS).subscribe(new Consumer() {
public final void accept(Object obj) {
HistroyDataService.AnonymousClass1.this.lambda$onError$0$HistroyDataService$1((Long) obj);
}
});
if (HistroyDataService.checkNetworkAvailable(HistroyDataService.this.getApplicationContext())) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(HistroyDataService.this.getApplicationContext(), HistroyDataService.this.getString(R.string.network_error), 0).show();
}
});
} else {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Log.i("HistroyDataService", "lyq net_error 1 ----");
Toast.makeText(HistroyDataService.this.getApplicationContext(), HistroyDataService.this.getString(R.string.net_error), 0).show();
}
});
}
}
public void lambda$onError$0$HistroyDataService$1(Long l) throws Exception {
HistroyDataService.this.getHistory();
}
@Override
public void onBusinessNext(ResponseData<HistoryResult> data) {
System.out.println("lyq 获取历史数据 成功 ----");
try {
HistoryResult content = data.getContent();
if (content != null && DaoHadle.getUser() != null) {
List<DeviceWeather> data2 = content.getData();
DaoHadle.insertHistoryWeather(data2);
HistroyDataService.access$014(HistroyDataService.this, data2.size());
int totalElements = (int) (((HistroyDataService.this.historyNum * 1.0d) / (content.getPage().getTotalElements() + HistroyDataService.this.historyNum)) * 100.0d);
System.out.println("lyq historyNum = " + HistroyDataService.this.historyNum + " totalNum = " + (content.getPage().getTotalElements() + HistroyDataService.this.historyNum) + " percent = " + totalElements);
Intent intent = new Intent();
if (data2.size() == 50) {
System.out.println("lyq requestHistory size == 50");
SharedPreUtils.putBoolean(HistroyDataService.this.getApplicationContext(), SharedPre.History.LOAD_ALL, false);
intent.setAction(DataDownloadReceiver.DATA_DOWNLOADING_ACTION);
intent.putExtra(DataDownloadReceiver.DATA_DOWNLOAD_PERCENT, totalElements + "%");
HistroyDataService.this.sendBroadcast(intent);
HistroyDataService.this.pageResult.setStartTime(data2.get(data2.size() - 1).getTime().longValue() / 1000);
SharedPreUtils.putLong(HistroyDataService.this.getApplicationContext(), SharedPre.User.LAST_UPDATE_HISTORY_TIME, HistroyDataService.this.pageResult.getStartTime());
HistroyDataService.this.getHistory();
} else {
System.out.println("lyq requestHistory size != 50");
HistroyDataService.this.pageResult.setStartTime(HistroyDataService.this.pageResult.getEndTime());
SharedPreUtils.putLong(HistroyDataService.this.getApplicationContext(), SharedPre.User.LAST_UPDATE_HISTORY_TIME, HistroyDataService.this.pageResult.getEndTime());
SharedPreUtils.putBoolean(HistroyDataService.this.getApplicationContext(), SharedPre.History.LOAD_ALL, true);
intent.setAction(DataDownloadReceiver.DATA_DOWNLOAD_SUCCESS_ACTION);
HistroyDataService.this.sendBroadcast(intent);
HistroyDataService.stopService(HistroyDataService.this.getApplicationContext());
HistroyDataService.this.pageResult.setEndTime(System.currentTimeMillis() / 1000);
}
}
} catch (Exception unused) {
}
}
}
@Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onDestroy() {
super.onDestroy();
Disposable disposable = this.disposable;
if (disposable == null || disposable.isDisposed()) {
return;
}
this.disposable.dispose();
this.disposable = null;
}
}