version:1.1.2 Huaruian
fix: update:增加检查更新
This commit is contained in:
@@ -153,6 +153,8 @@ public class MainAPresenter implements MainAContact.Presenter {
|
||||
mView.checkTestUpdateFinish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Log.e(TAG, "checkTestUpdate: tag is Empty");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,12 +162,12 @@ public class MainAPresenter implements MainAContact.Presenter {
|
||||
public void getDefaultDesktop() {
|
||||
Log.e(TAG, "getDefaultDesktop: ");
|
||||
if (JGYUtils.isOfficialVersion() || !JGYUtils.getInstance().getDeviceIsLocked()) {
|
||||
Log.e(TAG, "getDefaultDesktop: "+"Device unLocked");
|
||||
Log.e(TAG, "getDefaultDesktop: " + "Device unLocked");
|
||||
mView.getDefaultDesktopFinish();
|
||||
} else {
|
||||
int aihuaUnlock = Settings.System.getInt(mContext.getContentResolver(), CommonConfig.AIHUA_UNLOCK, 0);
|
||||
if (JGYUtils.getInstance().isAihuaFramwwork() && aihuaUnlock == 1) {
|
||||
Log.e(TAG, "getDefaultDesktop: "+"Device aihua");
|
||||
Log.e(TAG, "getDefaultDesktop: " + "Device aihua");
|
||||
mView.getDefaultDesktopFinish();
|
||||
} else {
|
||||
NetInterfaceManager.getInstance()
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -32,6 +33,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import com.aoleyun.sn.BuildConfig;
|
||||
import com.aoleyun.sn.R;
|
||||
import com.aoleyun.sn.activity.requestlog.RequestLogActivity;
|
||||
import com.aoleyun.sn.activity.update.UpdateActivity;
|
||||
import com.aoleyun.sn.base.BaseActivity;
|
||||
import com.aoleyun.sn.bean.StudentsInfo;
|
||||
import com.aoleyun.sn.comm.CommonConfig;
|
||||
@@ -72,6 +74,8 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
|
||||
ImageView back;
|
||||
@BindView(R.id.tv_version)
|
||||
TextView tv_version;
|
||||
@BindView(R.id.bt_update)
|
||||
Button bt_update;
|
||||
@BindView(R.id.iv_head)
|
||||
ImageView iv_head;
|
||||
@BindView(R.id.tv_name)
|
||||
@@ -206,6 +210,12 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
|
||||
cl_class.setVisibility(View.VISIBLE);
|
||||
cl_number_name.setVisibility(View.GONE);
|
||||
}
|
||||
bt_update.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
startActivity(new Intent(MainActivity.this, UpdateActivity.class));
|
||||
}
|
||||
});
|
||||
// setStoreUpdateListener(bt_checkupdate);
|
||||
registerReceiver();
|
||||
}
|
||||
@@ -483,6 +493,7 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
|
||||
|
||||
@Override
|
||||
public void checkAoleyunUpdateFinish() {
|
||||
Log.e(TAG, "checkAoleyunUpdateFinish: ");
|
||||
mMainAPresenter.checkTestUpdate();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.aoleyun.sn.activity.update;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.aoleyun.sn.R;
|
||||
import com.aoleyun.sn.adapter.AppUpdateAdapter;
|
||||
import com.aoleyun.sn.base.BaseActivity;
|
||||
import com.aoleyun.sn.bean.AppUpdateInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class UpdateActivity extends BaseActivity implements UpdateContact.UpdateView {
|
||||
|
||||
private static final String TAG = UpdateActivity.class.getSimpleName();
|
||||
@BindView(R.id.root)
|
||||
ConstraintLayout root;
|
||||
@BindView(R.id.main)
|
||||
ConstraintLayout main;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
@BindView(R.id.cl_nodata)
|
||||
ConstraintLayout cl_nodata;
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
|
||||
private UpdatePresenter mPresenter;
|
||||
private AppUpdateAdapter mAppUpdateAdapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_update;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mPresenter = new UpdatePresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
|
||||
mAppUpdateAdapter = new AppUpdateAdapter();
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(UpdateActivity.this));
|
||||
recyclerView.setAdapter(mAppUpdateAdapter);
|
||||
root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
main.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
}
|
||||
});
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
registmNewAppReceiver();
|
||||
mPresenter.checkAllAppUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mPresenter.detachView();
|
||||
if (mNewAppReceiver != null) {
|
||||
unregisterReceiver(mNewAppReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppUpdate(List<AppUpdateInfo> updateApp) {
|
||||
if (updateApp == null || updateApp.size() == 0) {
|
||||
cl_nodata.setVisibility(View.VISIBLE);
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
} else {
|
||||
cl_nodata.setVisibility(View.GONE);
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
mAppUpdateAdapter.setAppInfoList(updateApp);
|
||||
}
|
||||
}
|
||||
|
||||
private void registmNewAppReceiver() {
|
||||
mNewAppReceiver = new NewAppReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||
filter.addDataScheme("package");
|
||||
registerReceiver(mNewAppReceiver, filter);
|
||||
}
|
||||
|
||||
private NewAppReceiver mNewAppReceiver;
|
||||
|
||||
class NewAppReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.e(TAG, "onReceive: " + action);
|
||||
if (Intent.ACTION_PACKAGE_ADDED.equals(action)
|
||||
|| Intent.ACTION_PACKAGE_REMOVED.equals(action)
|
||||
|| Intent.ACTION_PACKAGE_REPLACED.equals(action)
|
||||
|| Intent.ACTION_PACKAGE_CHANGED.equals(action)
|
||||
) {
|
||||
mAppUpdateAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.aoleyun.sn.activity.update;
|
||||
|
||||
import com.aoleyun.sn.base.BasePresenter;
|
||||
import com.aoleyun.sn.base.BaseView;
|
||||
import com.aoleyun.sn.bean.AppUpdateInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UpdateContact {
|
||||
interface Presenter extends BasePresenter<UpdateView> {
|
||||
/*获取所有更新*/
|
||||
void checkAllAppUpdate();
|
||||
}
|
||||
|
||||
|
||||
public interface UpdateView extends BaseView {
|
||||
void onAppUpdate(List<AppUpdateInfo> updateApp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.aoleyun.sn.activity.update;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.aoleyun.sn.bean.AppUpdateInfo;
|
||||
import com.aoleyun.sn.network.NetInterfaceManager;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public class UpdatePresenter implements UpdateContact.Presenter {
|
||||
private Context mContext;
|
||||
|
||||
UpdatePresenter(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
private UpdateContact.UpdateView mView;
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(UpdateContact.UpdateView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkAllAppUpdate() {
|
||||
NetInterfaceManager.getInstance().checkAoleyunUpdate( getLifecycle(), new NetInterfaceManager.UpdateCallback() {
|
||||
@Override
|
||||
public void onUpdate(List<AppUpdateInfo> appUpdateInfos) {
|
||||
mView.onAppUpdate(appUpdateInfos);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
180
app/src/main/java/com/aoleyun/sn/adapter/AppUpdateAdapter.java
Normal file
180
app/src/main/java/com/aoleyun/sn/adapter/AppUpdateAdapter.java
Normal file
@@ -0,0 +1,180 @@
|
||||
package com.aoleyun.sn.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.aoleyun.sn.BuildConfig;
|
||||
import com.aoleyun.sn.R;
|
||||
import com.aoleyun.sn.bean.AppUpdateInfo;
|
||||
import com.aoleyun.sn.comm.PackageNames;
|
||||
import com.aoleyun.sn.gson.GsonUtils;
|
||||
import com.aoleyun.sn.utils.ApkUtils;
|
||||
import com.aoleyun.sn.utils.JGYUtils;
|
||||
import com.aoleyun.sn.utils.ToastUtil;
|
||||
import com.aoleyun.sn.utils.Utils;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AppUpdateAdapter extends RecyclerView.Adapter<AppUpdateAdapter.Holder> {
|
||||
private static final String TAG = AppUpdateAdapter.class.getSimpleName();
|
||||
|
||||
private Context mContext;
|
||||
private List<AppUpdateInfo> mAppInfoList;
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mContext = parent.getContext();
|
||||
mPackageManager = mContext.getPackageManager();
|
||||
return new Holder(LayoutInflater.from(mContext).inflate(R.layout.item_app_update, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull Holder holder, int position) {
|
||||
AppUpdateInfo appInfo = mAppInfoList.get(position);
|
||||
String pkg = appInfo.getPackages();
|
||||
Drawable drawable;
|
||||
switch (pkg) {
|
||||
case BuildConfig.APPLICATION_ID:
|
||||
drawable = mContext.getDrawable(R.mipmap.ic_launcher);
|
||||
break;
|
||||
case PackageNames.APPSTORE:
|
||||
drawable = mContext.getDrawable(R.drawable.com_aoleyun_appstore);
|
||||
break;
|
||||
case PackageNames.DESKTOP:
|
||||
drawable = mContext.getDrawable(R.drawable.com_aoleyun_os);
|
||||
break;
|
||||
case PackageNames.NOTIFICATIONS:
|
||||
drawable = mContext.getDrawable(R.drawable.com_aoleyun_info);
|
||||
break;
|
||||
case PackageNames.BROWSER:
|
||||
drawable = mContext.getDrawable(R.drawable.com_aoleyun_browser);
|
||||
break;
|
||||
default:
|
||||
drawable = mContext.getDrawable(R.drawable.exit_icon);
|
||||
}
|
||||
Glide.with(mContext).load(drawable).into(holder.imageView);
|
||||
if (!TextUtils.isEmpty(appInfo.getApp_name())) {
|
||||
holder.tv_app_name.setText(appInfo.getApp_name());
|
||||
}
|
||||
if (!TextUtils.isEmpty(appInfo.getVersion_name())) {
|
||||
holder.tv_app_version.setText("更新版本:" + appInfo.getVersion_name());
|
||||
}
|
||||
holder.tv_local_version.setText("安装版本:" + installedVersion(pkg));
|
||||
if (ApkUtils.isAvailable(mContext, appInfo.getPackages())) {
|
||||
if (isUpdate(appInfo)) {
|
||||
holder.bt_update.setEnabled(true);
|
||||
holder.bt_update.setText("更新");
|
||||
holder.bt_update.setBackground(mContext.getDrawable(R.drawable.bt_activation_selector));
|
||||
} else {
|
||||
holder.bt_update.setEnabled(false);
|
||||
holder.bt_update.setText("暂无");
|
||||
holder.bt_update.setBackground(mContext.getDrawable(R.drawable.bt_disable));
|
||||
}
|
||||
} else {
|
||||
holder.bt_update.setEnabled(true);
|
||||
holder.bt_update.setText("下载");
|
||||
holder.bt_update.setBackground(mContext.getDrawable(R.drawable.bt_activation_selector));
|
||||
}
|
||||
holder.bt_update.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
notifyDataSetChanged();
|
||||
if (isUpdate(appInfo)) {
|
||||
ToastUtil.show("开始下载:" + appInfo.getApp_name());
|
||||
JsonObject jsonObject = GsonUtils.getJsonObject(new Gson().toJson(appInfo));
|
||||
Utils.ariaDownload(mContext, appInfo.getUrl(), jsonObject);
|
||||
} else {
|
||||
ToastUtil.show(appInfo.getApp_name() + " 已是最新版本");
|
||||
Log.e(TAG, "onClick: 没有找到更新");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isUpdate(AppUpdateInfo appInfo) {
|
||||
String pkg = appInfo.getPackages();
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = mPackageManager.getPackageInfo(pkg, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (packageInfo == null) {
|
||||
//未安装
|
||||
Log.e(TAG, "getAllAppUpdateInfos: " + pkg);
|
||||
return true;
|
||||
} else {
|
||||
long appVersionCode;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
appVersionCode = packageInfo.getLongVersionCode();
|
||||
} else {
|
||||
appVersionCode = packageInfo.versionCode;
|
||||
}
|
||||
long versionCode = appInfo.getVersion_code();
|
||||
//版本升级
|
||||
return appVersionCode < versionCode;
|
||||
}
|
||||
}
|
||||
|
||||
private String installedVersion(String pkg) {
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = mPackageManager.getPackageInfo(pkg, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (packageInfo == null) {
|
||||
return "未安装";
|
||||
} else {
|
||||
return packageInfo.versionName;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAppInfoList(List<AppUpdateInfo> appInfoList) {
|
||||
this.mAppInfoList = appInfoList;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mAppInfoList == null ? 0 : mAppInfoList.size();
|
||||
}
|
||||
|
||||
class Holder extends RecyclerView.ViewHolder {
|
||||
|
||||
ImageView imageView;
|
||||
TextView tv_app_name;
|
||||
TextView tv_app_version;
|
||||
TextView tv_local_version;
|
||||
Button bt_update;
|
||||
|
||||
public Holder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
imageView = itemView.findViewById(R.id.imageView);
|
||||
tv_app_name = itemView.findViewById(R.id.tv_app_name);
|
||||
tv_app_version = itemView.findViewById(R.id.tv_app_version);
|
||||
tv_local_version = itemView.findViewById(R.id.tv_local_version);
|
||||
bt_update = itemView.findViewById(R.id.bt_update);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class BaseApplication extends MultiDexApplication {
|
||||
Log.e(TAG, "mmkv root: " + rootDir);
|
||||
|
||||
CrashReport.initCrashReport(getApplicationContext(), "b16b3c7f1a", false);
|
||||
CrashReport.setDeviceModel(this, Utils.getSerial(this));
|
||||
CrashReport.setDeviceId(this, Utils.getSerial(this));
|
||||
|
||||
PushManager.init(this);
|
||||
initRegisterObservable();
|
||||
|
||||
29
app/src/main/java/com/aoleyun/sn/bean/DownloadTaskInfo.java
Normal file
29
app/src/main/java/com/aoleyun/sn/bean/DownloadTaskInfo.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.aoleyun.sn.bean;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DownloadTaskInfo implements Serializable {
|
||||
private static final long serialVersionUID = -5406588064200275496L;
|
||||
|
||||
String app_name;
|
||||
@SerializedName(value = "app_package", alternate = {"package", "packages"})
|
||||
String app_package;
|
||||
|
||||
public String getApp_name() {
|
||||
return app_name;
|
||||
}
|
||||
|
||||
public void setApp_name(String app_name) {
|
||||
this.app_name = app_name;
|
||||
}
|
||||
|
||||
public String getApp_package() {
|
||||
return app_package;
|
||||
}
|
||||
|
||||
public void setApp_package(String app_package) {
|
||||
this.app_package = app_package;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ public class CommonConfig {
|
||||
|
||||
public static final String AES_KEY = "0123456789ABCDEF";
|
||||
|
||||
public static final String DEFAULT_DESKTOP_PACKAGE = "default_desktop_package_key";
|
||||
|
||||
/*爱华解锁标识*/
|
||||
public final static String AIHUA_UNLOCK = "Aihua_unlock_state";
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.functions.BiFunction;
|
||||
import io.reactivex.rxjava3.functions.Function5;
|
||||
import io.reactivex.rxjava3.functions.Function6;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
import okhttp3.Cache;
|
||||
@@ -827,6 +828,91 @@ public class NetInterfaceManager {
|
||||
});
|
||||
}
|
||||
|
||||
public interface UpdateCallback {
|
||||
void onUpdate(List<AppUpdateInfo> appUpdateInfos);
|
||||
}
|
||||
|
||||
synchronized public void checkAoleyunUpdate(BehaviorSubject<ActivityEvent> lifecycle, UpdateCallback callback) {
|
||||
Observable<BaseResponse<AppUpdateInfo>> infoUpdateObservable = NetInterfaceManager.getInstance()
|
||||
.getUpdateApi().getUpdate(BuildConfig.APPLICATION_ID, JGYUtils.getInstance().checkAppPlatform());
|
||||
Observable<BaseResponse<AppUpdateInfo>> storeUpdateObservable = NetInterfaceManager.getInstance()
|
||||
.getUpdateApi().getUpdate(PackageNames.APPSTORE, JGYUtils.getInstance().checkAppPlatform());
|
||||
Observable<BaseResponse<AppUpdateInfo>> desktopUpdateObservable = NetInterfaceManager.getInstance()
|
||||
.getUpdateApi().getUpdate(PackageNames.DESKTOP, JGYUtils.getInstance().checkAppPlatform());
|
||||
Observable<BaseResponse<AppUpdateInfo>> notifyUpdateObservable = NetInterfaceManager.getInstance()
|
||||
.getUpdateApi().getUpdate(PackageNames.NOTIFICATIONS, JGYUtils.getInstance().checkAppPlatform());
|
||||
Observable<BaseResponse<AppUpdateInfo>> browserUpdateObservable = NetInterfaceManager.getInstance()
|
||||
.getUpdateApi().getUpdate(PackageNames.BROWSER, JGYUtils.getInstance().checkAppPlatform());
|
||||
String desktop = mMMKV.decodeString(CommonConfig.DEFAULT_DESKTOP_PACKAGE);
|
||||
Observable<BaseResponse<AppUpdateInfo>> learningDesktopObservable = NetInterfaceManager.getInstance()
|
||||
.getUpdateApi().getUpdate(desktop, JGYUtils.getInstance().checkAppPlatform());
|
||||
Observable.zip(infoUpdateObservable, storeUpdateObservable, desktopUpdateObservable,
|
||||
notifyUpdateObservable, browserUpdateObservable, learningDesktopObservable,
|
||||
new Function6<BaseResponse<AppUpdateInfo>, BaseResponse<AppUpdateInfo>, BaseResponse<AppUpdateInfo>, BaseResponse<AppUpdateInfo>, BaseResponse<AppUpdateInfo>, BaseResponse<AppUpdateInfo>, List<AppUpdateInfo>>() {
|
||||
@Override
|
||||
public List<AppUpdateInfo> apply
|
||||
(BaseResponse<AppUpdateInfo> appUpdateInfoBaseResponse, BaseResponse<AppUpdateInfo> appUpdateInfoBaseResponse2, BaseResponse<AppUpdateInfo> appUpdateInfoBaseResponse3,
|
||||
BaseResponse<AppUpdateInfo> appUpdateInfoBaseResponse4, BaseResponse<AppUpdateInfo> appUpdateInfoBaseResponse5, BaseResponse<AppUpdateInfo> appUpdateInfoBaseResponse6) throws Throwable {
|
||||
List<AppUpdateInfo> appUpdateInfos = new ArrayList<>();
|
||||
if (appUpdateInfoBaseResponse.code == OK) {
|
||||
appUpdateInfos.add(appUpdateInfoBaseResponse.data);
|
||||
}
|
||||
if (appUpdateInfoBaseResponse2.code == OK) {
|
||||
appUpdateInfos.add(appUpdateInfoBaseResponse2.data);
|
||||
}
|
||||
if (appUpdateInfoBaseResponse3.code == OK) {
|
||||
appUpdateInfos.add(appUpdateInfoBaseResponse3.data);
|
||||
}
|
||||
if (appUpdateInfoBaseResponse4.code == OK) {
|
||||
appUpdateInfos.add(appUpdateInfoBaseResponse4.data);
|
||||
}
|
||||
if (appUpdateInfoBaseResponse5.code == OK) {
|
||||
appUpdateInfos.add(appUpdateInfoBaseResponse5.data);
|
||||
}
|
||||
if (appUpdateInfoBaseResponse6.code == OK) {
|
||||
appUpdateInfos.add(appUpdateInfoBaseResponse6.data);
|
||||
}
|
||||
return appUpdateInfos;
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<List<AppUpdateInfo>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("checkAoleyunUpdate", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull List<AppUpdateInfo> appUpdateInfos) {
|
||||
String jsonString = GsonUtils.toJSONString(appUpdateInfos);
|
||||
Log.e("checkAoleyunUpdate", "onNext: " + jsonString);
|
||||
if (appUpdateInfos != null && appUpdateInfos.size() != 0) {
|
||||
cacheHelper.put(UrlAddress.CHECK_UPDATE, jsonString);
|
||||
for (AppUpdateInfo info : appUpdateInfos) {
|
||||
JsonObject jsonObject = parseString(new Gson().toJson(info)).getAsJsonObject();
|
||||
JGYUtils.getInstance().installAPK(jsonObject);
|
||||
}
|
||||
} else {
|
||||
cacheHelper.put(UrlAddress.CHECK_UPDATE, "");
|
||||
}
|
||||
callback.onUpdate(appUpdateInfos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("checkAoleyunUpdate", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("checkAoleyunUpdate", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void checkUpdate() {
|
||||
String jsonString = cacheHelper.getAsString(UrlAddress.CHECK_UPDATE);
|
||||
Gson gson = new Gson();
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.aoleyun.sn.BuildConfig;
|
||||
import com.aoleyun.sn.KeepAliveConnection;
|
||||
import com.aoleyun.sn.R;
|
||||
import com.aoleyun.sn.bean.BaseResponse;
|
||||
import com.aoleyun.sn.bean.DownloadTaskInfo;
|
||||
import com.aoleyun.sn.bean.ForceDownloadData;
|
||||
import com.aoleyun.sn.comm.CommonConfig;
|
||||
import com.aoleyun.sn.comm.PackageNames;
|
||||
import com.aoleyun.sn.gson.GsonUtils;
|
||||
@@ -46,7 +48,9 @@ import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.baidu.location.LocationClient;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -54,6 +58,8 @@ import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
@@ -845,9 +851,13 @@ public class GuardService extends Service {
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@Download.onTaskRunning
|
||||
protected void running(DownloadTask task) {
|
||||
JsonObject jsonObject = GsonUtils.getJsonObject(task.getExtendField());
|
||||
String app_name = jsonObject.get("app_name").getAsString();
|
||||
String app_package = jsonObject.get("app_package").getAsString();
|
||||
String jsonString = task.getExtendField();
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<DownloadTaskInfo>() {
|
||||
}.getType();
|
||||
DownloadTaskInfo downloadTaskInfo = gson.fromJson(jsonString, listType);
|
||||
String app_name = downloadTaskInfo.getApp_name();
|
||||
String app_package = downloadTaskInfo.getApp_package();
|
||||
Log.e("aria", "正在下载:" + task.getPercent() + ":" + task.getExtendField());
|
||||
ToastUtil.show("正在下载:" + app_name + "-" + task.getPercent() + "%" + "\t" + Formatter.formatFileSize(GuardService.this, task.getSpeed()) + "/s");
|
||||
}
|
||||
@@ -861,9 +871,13 @@ public class GuardService extends Service {
|
||||
Log.e("taskComplete", "extendField::" + extendField);
|
||||
|
||||
if (filepath.endsWith("apk")) {
|
||||
JsonObject jsonObject = GsonUtils.getJsonObject(extendField);
|
||||
String app_name = jsonObject.get("app_name").getAsString();
|
||||
String app_package = jsonObject.get("app_package").getAsString();
|
||||
String jsonString = task.getExtendField();
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<DownloadTaskInfo>() {
|
||||
}.getType();
|
||||
DownloadTaskInfo downloadTaskInfo = gson.fromJson(jsonString, listType);
|
||||
String app_name = downloadTaskInfo.getApp_name();
|
||||
String app_package = downloadTaskInfo.getApp_package();
|
||||
ToastUtil.show(app_name + "\t:下载完成");
|
||||
if (filepath.endsWith(".xapk")) {
|
||||
XAPKUtils.getInstance().installXAPK(filepath);
|
||||
|
||||
@@ -1323,6 +1323,7 @@ public class JGYUtils {
|
||||
String app_url = jsonObject.get("app_url").getAsString();
|
||||
String app_package = jsonObject.get("app_package").getAsString();
|
||||
int app_version_code = jsonObject.get("app_version_code").getAsInt();
|
||||
mMMKV.encode(CommonConfig.DEFAULT_DESKTOP_PACKAGE, app_package);
|
||||
Set<String> desktop = new HashSet<>(ApkUtils.desktopAPP);
|
||||
desktop.remove(app_package);
|
||||
for (String s : desktop) {
|
||||
|
||||
Reference in New Issue
Block a user