update:2020.12.25
fix:新后台对接完成 add:
This commit is contained in:
97
.gitignore
vendored
97
.gitignore
vendored
@@ -1,14 +1,87 @@
|
||||
# Built application files
|
||||
*.apk
|
||||
*.aar
|
||||
*.ap_
|
||||
*.aab
|
||||
|
||||
# Files for the ART/Dalvik VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
out/
|
||||
# Uncomment the following line in case you need and you don't have the release build type files in your app
|
||||
# release/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Log Files
|
||||
*.log
|
||||
|
||||
# Android Studio Navigation editor temp files
|
||||
.navigation/
|
||||
|
||||
# Android Studio captures folder
|
||||
captures/
|
||||
|
||||
# IntelliJ
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/gradle.xml
|
||||
.idea/assetWizardSettings.xml
|
||||
.idea/dictionaries
|
||||
.idea/libraries
|
||||
# Android Studio 3 in .gitignore file.
|
||||
.idea/caches
|
||||
.idea/modules.xml
|
||||
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
|
||||
.idea/navEditor.xml
|
||||
|
||||
# Keystore files
|
||||
# Uncomment the following lines if you do not want to check your keystore files in.
|
||||
#*.jks
|
||||
#*.keystore
|
||||
|
||||
# External native build folder generated in Android Studio 2.2 and later
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
.cxx/
|
||||
|
||||
# Google Services (e.g. APIs or Firebase)
|
||||
# google-services.json
|
||||
|
||||
# Freeline
|
||||
freeline.py
|
||||
freeline/
|
||||
freeline_project_description.json
|
||||
|
||||
# fastlane
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots
|
||||
fastlane/test_output
|
||||
fastlane/readme.md
|
||||
|
||||
# Version control
|
||||
vcs.xml
|
||||
|
||||
# lint
|
||||
lint/intermediates/
|
||||
lint/generated/
|
||||
lint/outputs/
|
||||
lint/tmp/
|
||||
# lint/reports/
|
||||
/.idea/
|
||||
/.idea/libraries/
|
||||
|
||||
2
app/.gitignore
vendored
2
app/.gitignore
vendored
@@ -84,3 +84,5 @@ lint/outputs/
|
||||
lint/tmp/
|
||||
# lint/reports/
|
||||
/.idea/
|
||||
/.idea/libraries/
|
||||
/.idea/libraries/
|
||||
|
||||
@@ -104,54 +104,44 @@ dependencies {
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||
implementation "androidx.core:core-ktx:+"
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
//github第三方控件
|
||||
implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
|
||||
//下拉刷新控件
|
||||
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0' //1.0.5及以前版本的老用户升级需谨慎,API改动过大
|
||||
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0' //没有使用特殊Header,可以不加这行
|
||||
|
||||
//glide
|
||||
implementation 'com.github.bumptech.glide:glide:4.10.0'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
|
||||
//aria
|
||||
implementation 'com.arialyy.aria:core:3.7.7'
|
||||
annotationProcessor 'com.arialyy.aria:compiler:3.7.7'
|
||||
//OKGO
|
||||
//必须使用
|
||||
implementation 'com.lzy.net:okgo:3.0.4'
|
||||
//以下三个选择添加,okrx和okrx2不能同时使用
|
||||
implementation 'com.lzy.net:okrx:1.0.2'
|
||||
// compile 'com.lzy.net:okrx2:2.0.2'
|
||||
implementation 'com.lzy.net:okserver:2.0.5'
|
||||
|
||||
implementation 'com.alibaba:fastjson:1.2.21'
|
||||
|
||||
implementation 'com.blankj:utilcode:1.23.7'
|
||||
implementation 'com.arialyy.aria:core:3.8.5'
|
||||
annotationProcessor 'com.arialyy.aria:compiler:3.8.5'
|
||||
//动态权限框架
|
||||
implementation 'com.hjq:xxpermissions:6.0'
|
||||
|
||||
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
|
||||
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
|
||||
implementation 'io.reactivex:rxjava:1.2.2'
|
||||
implementation 'io.reactivex:rxandroid:1.2.1'
|
||||
|
||||
|
||||
//okhttp
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.6.0'
|
||||
//RxJava和Retrofit
|
||||
implementation 'io.reactivex.rxjava2:rxjava:2.2.5'
|
||||
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
|
||||
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
|
||||
//google
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation 'com.google.zxing:core:3.3.0'
|
||||
implementation 'com.alibaba:fastjson:1.2.21'
|
||||
//极光推送
|
||||
implementation 'cn.jiguang.sdk:jpush:3.4.1' // 此处以JPush 3.4.1 版本为例。
|
||||
implementation 'cn.jiguang.sdk:jcore:2.2.4' // 此处以JCore 2.2.4 版本为例。
|
||||
|
||||
//banner图
|
||||
implementation 'com.zhpan.library:bannerview:2.6.4'
|
||||
implementation "androidx.core:core-ktx:+"
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
|
||||
//更换字体框架
|
||||
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.appstore.uiui"
|
||||
android:sharedUserId="android.uid.system">
|
||||
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
|
||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
@@ -204,7 +203,7 @@
|
||||
</intent-filter>
|
||||
</service> <!-- User defined. For test only 用户自定义的广播接收器 -->
|
||||
<receiver
|
||||
android:name=".jpush.MyReceiver"
|
||||
android:name="com.appstore.uiui.jpush.MyReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间;
|
||||
对于3.4.1之前版本的未完成的老任务,依然采用原来的文件空间占用方式;
|
||||
-->
|
||||
<threadNum value="3"/>
|
||||
<threadNum value="1"/>
|
||||
|
||||
<!--设置下载队列最大任务数, 默认为2-->
|
||||
<maxTaskNum value="1"/>
|
||||
|
||||
@@ -19,10 +19,7 @@ import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.LogUtils;
|
||||
import com.appstore.uiui.utils.SPUtils;
|
||||
import com.appstore.uiui.utils.ToastUtil;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.FileCallback;
|
||||
import com.lzy.okgo.model.Progress;
|
||||
import com.lzy.okgo.model.Response;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
||||
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
|
||||
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
|
||||
@@ -83,13 +80,14 @@ public class MyApplication extends Application {
|
||||
JPushInterface.init(this); // 初始化 JPush
|
||||
app = this;
|
||||
ToastUtil.init(this);
|
||||
OkGo.getInstance().init(this)
|
||||
.setRetryCount(10)//重试次数
|
||||
;
|
||||
// OkGo.getInstance().init(this)
|
||||
// .setRetryCount(10)//重试次数
|
||||
// ;
|
||||
|
||||
Aria.init(this);
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
|
||||
|
||||
// AppUtil.getInstalledApp(this);
|
||||
// Aria.init(this);
|
||||
// Aria.download(this).register();
|
||||
if (!isDebug(this)) {
|
||||
catchException();
|
||||
}
|
||||
@@ -206,10 +204,10 @@ public class MyApplication extends Application {
|
||||
setAppLockedstate(EXTRA);
|
||||
break;
|
||||
case JIGUANG_FORCE_INSTALLAPK:
|
||||
intallApk(EXTRA);
|
||||
// intallApk(EXTRA);
|
||||
break;
|
||||
case JIGUANG_FORCE_UNINSTALLAPK:
|
||||
unintallApk(EXTRA);
|
||||
// unintallApk(EXTRA);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -375,62 +373,62 @@ public class MyApplication extends Application {
|
||||
}
|
||||
|
||||
//静默安装应用,使用okgo,断网会出现问题,等待修改使用aria
|
||||
synchronized private void intallApk(String jsondata) {
|
||||
try {
|
||||
JSONObject extra = new JSONObject(jsondata);
|
||||
final String packages = extra.getString("package");
|
||||
ToastUtil.debugShow("收到应用安装消息:包名" + packages);
|
||||
String url = extra.getString("url");
|
||||
OkGo.<File>get(url)
|
||||
.execute(new FileCallback() {
|
||||
@Override
|
||||
public void onSuccess(final Response<File> response) {
|
||||
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApkUtils.installApp(app.getAppContext(), response.body().getAbsolutePath());
|
||||
}
|
||||
}).start();
|
||||
LogUtils.e("onSuccess", "download file successful,now installing");
|
||||
}
|
||||
// synchronized private void intallApk(String jsondata) {
|
||||
// try {
|
||||
// JSONObject extra = new JSONObject(jsondata);
|
||||
// final String packages = extra.getString("package");
|
||||
// ToastUtil.debugShow("收到应用安装消息:包名" + packages);
|
||||
// String url = extra.getString("url");
|
||||
// OkGo.<File>get(url)
|
||||
// .execute(new FileCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(final Response<File> response) {
|
||||
//// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
||||
// new Thread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// ApkUtils.installApp(app.getAppContext(), response.body().getAbsolutePath());
|
||||
// }
|
||||
// }).start();
|
||||
// LogUtils.e("onSuccess", "download file successful,now installing");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<File> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("manageCustomMessage", "File download Failure");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void downloadProgress(Progress progress) {
|
||||
// super.downloadProgress(progress);
|
||||
// LogUtils.e("downloadProgress", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// } catch (JSONException e) {
|
||||
// e.printStackTrace();
|
||||
// LogUtils.e("intallApk", e.getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onError(Response<File> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("manageCustomMessage", "File download Failure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadProgress(Progress progress) {
|
||||
super.downloadProgress(progress);
|
||||
LogUtils.e("downloadProgress", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
LogUtils.e("intallApk", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
synchronized private void unintallApk(String json) {
|
||||
String sn_id = (String) SPUtils.get(getApplicationContext(), "sn_id", "-1");
|
||||
try {
|
||||
JSONObject object = new JSONObject(json);
|
||||
String packageName = object.getString("package");
|
||||
ToastUtil.debugShow("收到应用卸载消息:包名" + packageName);
|
||||
if (!packageName.equals("") && !packageName.equals(getApplicationContext().getPackageName())) {
|
||||
if (!ApkUtils.isAvailable(getApplicationContext(), packageName)) {
|
||||
OKGO.setAppuninstallInfo(sn_id, packageName);
|
||||
} else {
|
||||
ApkUtils.deleteApkInSilence(packageName);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
LogUtils.e("unintallApk", e.getMessage());
|
||||
}
|
||||
}
|
||||
// synchronized private void unintallApk(String json) {
|
||||
// String sn_id = (String) SPUtils.get(getApplicationContext(), "sn_id", "-1");
|
||||
// try {
|
||||
// JSONObject object = new JSONObject(json);
|
||||
// String packageName = object.getString("package");
|
||||
// ToastUtil.debugShow("收到应用卸载消息:包名" + packageName);
|
||||
// if (!packageName.equals("") && !packageName.equals(getApplicationContext().getPackageName())) {
|
||||
// if (!ApkUtils.isAvailable(getApplicationContext(), packageName)) {
|
||||
// OKGO.setAppuninstallInfo(sn_id, packageName);
|
||||
// } else {
|
||||
// ApkUtils.deleteApkInSilence(packageName);
|
||||
// }
|
||||
// }
|
||||
// } catch (JSONException e) {
|
||||
// e.printStackTrace();
|
||||
// LogUtils.e("unintallApk", e.getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.Button;
|
||||
import android.widget.ImageView;
|
||||
@@ -13,6 +14,8 @@ import android.widget.TextView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.appstore.uiui.R;
|
||||
import com.appstore.uiui.adapter.ImageAdapter;
|
||||
import com.appstore.uiui.base.BaseActivity;
|
||||
@@ -20,14 +23,15 @@ import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.bean.GlideCircleWithBorder;
|
||||
import com.appstore.uiui.helper.CustomSnapHelper;
|
||||
import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.FileUtils;
|
||||
import com.appstore.uiui.utils.StorageUtils;
|
||||
import com.appstore.uiui.utils.ToastUtil;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.model.Progress;
|
||||
import com.lzy.okgo.request.GetRequest;
|
||||
import com.lzy.okserver.OkDownload;
|
||||
import com.lzy.okserver.download.DownloadListener;
|
||||
import com.lzy.okserver.download.DownloadTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -67,26 +71,27 @@ public class DetailsActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
Aria.download(this).register();
|
||||
appInfo = (AppInfo) getIntent().getSerializableExtra("appinfo");
|
||||
if (appInfo == null) {
|
||||
ToastUtil.show("获取引用信息失败,返回重试");
|
||||
return;
|
||||
}
|
||||
final DownloadTask downloadTask = OkDownload.getInstance().getTask(appInfo.getApp_url());
|
||||
if (downloadTask != null) {
|
||||
downloadTask.register(new FileDownloadListener(appInfo.getApp_url()));
|
||||
refresh(downloadTask.progress);
|
||||
}
|
||||
// final DownloadTask downloadTask = OkDownload.getInstance().getTask(appInfo.getApp_url());
|
||||
// if (downloadTask != null) {
|
||||
// downloadTask.register(new FileDownloadListener(appInfo.getApp_url()));
|
||||
// refresh(downloadTask.progress);
|
||||
// }
|
||||
// tv_title.setText(appInfo.getApp_name());
|
||||
tv_name.setText(appInfo.getApp_name());
|
||||
tv_company.setText(appInfo.getApp_developer());
|
||||
detali_tv_size.setText("大小\t" + "(" + appInfo.getApp_size() + "MB" + ")");
|
||||
detali_tv_size.setText("大小\t" + "(" + StorageUtils.byteToMB(appInfo.getApp_size()) + ")");
|
||||
detail_tv_Developers.setText("开发者\t" + appInfo.getApp_developer());
|
||||
tv_update_time.setText("时间\t" + appInfo.getCreatetime());
|
||||
tv_version.setText("版本\t" + appInfo.getApp_version_name());
|
||||
tv_content.setText(appInfo.getApp_desc());
|
||||
rating_bar.setRating((float) appInfo.getApp_score());
|
||||
Glide.with(this).asBitmap().load(appInfo.getApp_img()) .transform(new GlideCircleWithBorder(this))
|
||||
Glide.with(this).asBitmap().load(appInfo.getApp_img()).transform(new GlideCircleWithBorder(this))
|
||||
.into(iv_icon);
|
||||
List<String> list = new ArrayList<String>() {{
|
||||
this.add(appInfo.getApp_preview1());
|
||||
@@ -98,34 +103,91 @@ public class DetailsActivity extends BaseActivity {
|
||||
rv_image.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
|
||||
CustomSnapHelper snapHelper = new CustomSnapHelper();
|
||||
snapHelper.attachToRecyclerView(rv_image);
|
||||
if (appInfo.isInstall()) {
|
||||
if (appInfo.isUpdate()) {
|
||||
tv_download.setText("更新" + "(" + appInfo.getApp_size() + "MB" + ")");
|
||||
final boolean installed = ApkUtils.isInstalled(DetailsActivity.this, appInfo.getApp_package());
|
||||
final boolean update = ApkUtils.isUpdate(DetailsActivity.this, appInfo.getApp_package(), appInfo.getApp_version_code());
|
||||
if (installed) {
|
||||
if (update) {
|
||||
tv_download.setText("更新" + "(" + StorageUtils.byteToMB(appInfo.getApp_size()) + ")");
|
||||
} else {
|
||||
tv_download.setText("打开");
|
||||
}
|
||||
} else {
|
||||
tv_download.setText("安装" + "(" + appInfo.getApp_size() + "MB" + ")");
|
||||
tv_download.setText("安装" + "(" + StorageUtils.byteToMB(appInfo.getApp_size()) + ")");
|
||||
}
|
||||
tv_download.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (appInfo.isInstall() && !appInfo.isUpdate()) {
|
||||
if (installed && !update) {
|
||||
ApkUtils.openApp(DetailsActivity.this, appInfo.getApp_package());
|
||||
} else {
|
||||
GetRequest<File> request = OkGo.get(appInfo.getApp_url());
|
||||
//这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag
|
||||
OkDownload.request(appInfo.getApp_url(), request)//
|
||||
// .priority(apk.priority)//
|
||||
.extra1(appInfo)//
|
||||
.save()//
|
||||
.register(new FileDownloadListener(appInfo.getApp_url()))//
|
||||
.start();
|
||||
// GetRequest<File> request = OkGo.get(appInfo.getApp_url());
|
||||
// //这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag
|
||||
// OkDownload.request(appInfo.getApp_url(), request)//
|
||||
//// .priority(apk.priority)//
|
||||
// .extra1(appInfo)//
|
||||
// .save()//
|
||||
// .register(new FileDownloadListener(appInfo.getApp_url()))//
|
||||
// .start();
|
||||
DownloadEntity entity = Aria.download(this).getFirstDownloadEntity(appInfo.getApp_url());
|
||||
if (null != entity) {
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_OTHER:
|
||||
case IEntity.STATE_FAIL:
|
||||
case IEntity.STATE_STOP:
|
||||
case IEntity.STATE_WAIT:
|
||||
case IEntity.STATE_CANCEL:
|
||||
Aria.download(this).load(entity.getId()).resume();
|
||||
break;
|
||||
case IEntity.STATE_RUNNING:
|
||||
Aria.download(this).load(entity.getId()).stop();
|
||||
break;
|
||||
case IEntity.STATE_PRE:
|
||||
break;
|
||||
case IEntity.STATE_POST_PRE:
|
||||
break;
|
||||
case IEntity.STATE_COMPLETE:
|
||||
File file = new File(entity.getFilePath());
|
||||
if (file.exists()) {
|
||||
tv_download.setText("安装中");
|
||||
ApkUtils.installApp(DetailsActivity.this, entity.getFilePath());
|
||||
} else {
|
||||
Aria.download(this).load(entity.getId()).cancel(true);
|
||||
JSONObject jsonObject = (JSONObject) JSON.toJSON(appInfo);
|
||||
FileUtils.ariaDownload(DetailsActivity.this, appInfo.getApp_url(), jsonObject);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void refresh(DownloadTask task) {
|
||||
if (appInfo.getApp_url().equals(task.getEntity().getUrl())) {
|
||||
switch (task.getState()) {
|
||||
case IEntity.STATE_OTHER:
|
||||
tv_download.setText("安装");
|
||||
break;
|
||||
case IEntity.STATE_STOP:
|
||||
tv_download.setText("继续");
|
||||
break;
|
||||
case IEntity.STATE_FAIL:
|
||||
tv_download.setText("出错");
|
||||
break;
|
||||
case IEntity.STATE_WAIT:
|
||||
tv_download.setText("等待");
|
||||
break;
|
||||
case IEntity.STATE_COMPLETE:
|
||||
tv_download.setText("安装中");
|
||||
break;
|
||||
case IEntity.STATE_RUNNING:
|
||||
tv_download.setText(task.getPercent() + "%");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setListener() {
|
||||
if (myReceiver == null) {
|
||||
@@ -143,71 +205,71 @@ public class DetailsActivity extends BaseActivity {
|
||||
finish();
|
||||
}
|
||||
|
||||
public void refresh(Progress progress) {
|
||||
switch (progress.status) {
|
||||
case Progress.NONE:
|
||||
tv_download.setText("安装" + "(" + appInfo.getApp_size() + "MB" + ")");
|
||||
break;
|
||||
case Progress.PAUSE:
|
||||
tv_download.setText("继续");
|
||||
break;
|
||||
case Progress.ERROR:
|
||||
tv_download.setText("出错");
|
||||
break;
|
||||
case Progress.WAITING:
|
||||
tv_download.setText("等待");
|
||||
break;
|
||||
case Progress.LOADING:
|
||||
tv_download.setText((int) (progress.fraction * 100) + "%");
|
||||
break;
|
||||
case Progress.FINISH:
|
||||
tv_download.setText("安装中");
|
||||
break;
|
||||
}
|
||||
}
|
||||
// public void refresh(Progress progress) {
|
||||
// switch (progress.status) {
|
||||
// case Progress.NONE:
|
||||
// tv_download.setText("安装" + "(" + appInfo.getApp_size() + "MB" + ")");
|
||||
// break;
|
||||
// case Progress.PAUSE:
|
||||
// tv_download.setText("继续");
|
||||
// break;
|
||||
// case Progress.ERROR:
|
||||
// tv_download.setText("出错");
|
||||
// break;
|
||||
// case Progress.WAITING:
|
||||
// tv_download.setText("等待");
|
||||
// break;
|
||||
// case Progress.LOADING:
|
||||
// tv_download.setText((int) (progress.fraction * 100) + "%");
|
||||
// break;
|
||||
// case Progress.FINISH:
|
||||
// tv_download.setText("安装中");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
class FileDownloadListener extends DownloadListener {
|
||||
|
||||
public FileDownloadListener(Object tag) {
|
||||
super(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Progress progress) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(Progress progress) {
|
||||
if (tag == appInfo.getApp_url()) {
|
||||
refresh(progress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Progress progress) {
|
||||
Throwable throwable = progress.exception;
|
||||
if (throwable != null) throwable.printStackTrace();
|
||||
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败,请重试");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(final File file, Progress progress) {
|
||||
tv_download.setText("安装中");
|
||||
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成");
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApkUtils.installApp(DetailsActivity.this, file.getAbsolutePath());
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(Progress progress) {
|
||||
|
||||
}
|
||||
}
|
||||
// class FileDownloadListener extends DownloadListener {
|
||||
//
|
||||
// public FileDownloadListener(Object tag) {
|
||||
// super(tag);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onStart(Progress progress) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onProgress(Progress progress) {
|
||||
// if (tag == appInfo.getApp_url()) {
|
||||
// refresh(progress);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Progress progress) {
|
||||
// Throwable throwable = progress.exception;
|
||||
// if (throwable != null) throwable.printStackTrace();
|
||||
// ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败,请重试");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFinish(final File file, Progress progress) {
|
||||
// tv_download.setText("安装中");
|
||||
// ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成");
|
||||
// new Thread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// ApkUtils.installApp(DetailsActivity.this, file.getAbsolutePath());
|
||||
// }
|
||||
// }).start();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onRemove(Progress progress) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
public class installReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
@@ -217,7 +279,6 @@ public class DetailsActivity extends BaseActivity {
|
||||
if (action.equals("com.appstore.uiui.PACKAGE_ADDED") || action.equals("com.appstore.uiui.PACKAGE_REPLACED")) {
|
||||
String packageName = intent.getStringExtra("package");
|
||||
if (packageName.equalsIgnoreCase(appInfo.getApp_package())) {
|
||||
appInfo.setInstall(true);
|
||||
tv_download.setText("打开");
|
||||
}
|
||||
}
|
||||
@@ -230,6 +291,54 @@ public class DetailsActivity extends BaseActivity {
|
||||
super.onDestroy();
|
||||
if (myReceiver != null) {
|
||||
unregisterReceiver(myReceiver);
|
||||
Aria.download(this).unRegister();
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskRunning
|
||||
void onTaskRunning(DownloadTask task) {
|
||||
refresh(task);
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
void onTaskComplete(DownloadTask task) {
|
||||
refresh(task);
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
void onTaskFail(DownloadTask task, Exception e) {
|
||||
refresh(task);
|
||||
}
|
||||
|
||||
@Download.onWait
|
||||
void onWait(DownloadTask task) {
|
||||
refresh(task);
|
||||
}
|
||||
|
||||
@Download.onTaskStart
|
||||
void onTaskStart(DownloadTask task) {
|
||||
refresh(task);
|
||||
}
|
||||
|
||||
@Download.onPre
|
||||
void onPre(DownloadTask task) {
|
||||
refresh(task);
|
||||
}
|
||||
|
||||
@Download.onTaskResume
|
||||
void onTaskResume(DownloadTask task) {
|
||||
refresh(task);
|
||||
}
|
||||
|
||||
@Download.onTaskStop
|
||||
void onTaskStop(DownloadTask task) {
|
||||
refresh(task);
|
||||
}
|
||||
|
||||
@Download.onTaskCancel
|
||||
void onTaskCancel(DownloadTask task) {
|
||||
refresh(task);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.appstore.uiui.activity;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.View;
|
||||
import android.widget.Adapter;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -11,23 +10,14 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.appstore.uiui.R;
|
||||
import com.appstore.uiui.adapter.AppAdapter;
|
||||
import com.appstore.uiui.adapter.DownloadManagerAdapter;
|
||||
import com.appstore.uiui.base.BaseActivity;
|
||||
import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.ToastUtil;
|
||||
import com.lzy.okgo.model.Progress;
|
||||
import com.lzy.okserver.OkDownload;
|
||||
import com.lzy.okserver.download.DownloadListener;
|
||||
import com.lzy.okserver.task.XExecutor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DownloadManagerActivity extends BaseActivity implements XExecutor.OnAllTaskEndListener {
|
||||
public class DownloadManagerActivity extends BaseActivity /*implements XExecutor.OnAllTaskEndListener*/ {
|
||||
private RecyclerView recyclerView;
|
||||
private DownloadManagerAdapter adapter;
|
||||
private OkDownload okDownload;
|
||||
// private OkDownload okDownload;
|
||||
private ImageView iv_notask;
|
||||
|
||||
@Override
|
||||
@@ -44,11 +34,12 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
okDownload = OkDownload.getInstance();
|
||||
// okDownload = OkDownload.getInstance();
|
||||
adapter = new DownloadManagerAdapter(this, handler);
|
||||
adapter.updateData(DownloadManagerAdapter.TYPE_ING);
|
||||
// adapter.updateData(DownloadManagerAdapter.TYPE_ING);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setAdapter(adapter);
|
||||
adapter.updateNotCompleteTask();
|
||||
if (adapter.getItemCount() == 0) {
|
||||
iv_notask.setVisibility(View.VISIBLE);
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
@@ -56,7 +47,7 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
|
||||
iv_notask.setVisibility(View.GONE);
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
okDownload.addOnAllTaskEndListener(this);
|
||||
// okDownload.addOnAllTaskEndListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,18 +56,18 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAllTaskEnd() {
|
||||
ToastUtil.show("所有任务已完成");
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
// @Override
|
||||
// public void onAllTaskEnd() {
|
||||
// ToastUtil.show("所有任务已完成");
|
||||
// adapter.notifyDataSetChanged();
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
okDownload.removeOnAllTaskEndListener(this);
|
||||
adapter.unRegister();
|
||||
// okDownload.removeOnAllTaskEndListener(this);
|
||||
// adapter.unRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,7 +85,7 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
|
||||
public void handleMessage(@NonNull Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (msg.what == 100) {
|
||||
adapter.updateData(DownloadManagerAdapter.TYPE_ING);
|
||||
// adapter.updateData(DownloadManagerAdapter.TYPE_ING);
|
||||
adapter.notifyDataSetChanged();
|
||||
if (adapter.getItemCount() == 0) {
|
||||
iv_notask.setVisibility(View.VISIBLE);
|
||||
|
||||
@@ -29,7 +29,8 @@ import java.util.List;
|
||||
public class KindDetailActivity extends BaseActivity implements RefreshManager.RefreshInterface {
|
||||
private TextView title;
|
||||
private String name;
|
||||
private int subject, grade, type = 0;
|
||||
private int subject, type = 0;
|
||||
private String grade;
|
||||
private SmartRefreshLayout mRefreshLayout;
|
||||
private RecyclerView detail_rv;
|
||||
private AppAdapter adapter;
|
||||
@@ -57,10 +58,10 @@ public class KindDetailActivity extends BaseActivity implements RefreshManager.R
|
||||
if (name.equals("娱乐")) {
|
||||
type = 1;
|
||||
}
|
||||
grade = (int) SPUtils.get(this, "sn_grade", 0);
|
||||
grade = (String) SPUtils.get(this, "sn_grade", "");
|
||||
title.setText(name);
|
||||
RefreshManager.getInstance().register(this);
|
||||
adapter = new AppAdapter(AppInfoList, false, getApplicationContext());
|
||||
adapter = new AppAdapter(AppInfoList, KindDetailActivity.this);
|
||||
adapter.setHasStableIds(true);
|
||||
detail_rv.setAdapter(adapter);
|
||||
detail_rv.setLayoutManager(new LinearLayoutManager(this));
|
||||
@@ -69,10 +70,10 @@ public class KindDetailActivity extends BaseActivity implements RefreshManager.R
|
||||
mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh(RefreshLayout refreshlayout) {
|
||||
OKGO.getSortApp(handler, type, grade, subject);
|
||||
// OKGO.getSortApp(handler, type, grade, subject);
|
||||
}
|
||||
});
|
||||
OKGO.getSortApp(handler, type, grade, subject);
|
||||
// OKGO.getSortApp(handler, type, grade, subject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,7 +92,7 @@ public class KindDetailActivity extends BaseActivity implements RefreshManager.R
|
||||
switch (msg.what) {
|
||||
case 1:
|
||||
AppInfoList = (List<AppInfo>) msg.obj;
|
||||
adapter.setData(checkUpdateOrInstalled(AppInfoList));
|
||||
adapter.setData(AppInfoList);
|
||||
adapter.notifyDataSetChanged();
|
||||
mImageView.setVisibility(View.GONE);
|
||||
detail_rv.setVisibility(View.VISIBLE);
|
||||
@@ -106,13 +107,6 @@ public class KindDetailActivity extends BaseActivity implements RefreshManager.R
|
||||
}
|
||||
};
|
||||
|
||||
public List<AppInfo> checkUpdateOrInstalled(List<AppInfo> list) {
|
||||
for (AppInfo appInfo : list) {
|
||||
appInfo.setInstall(ApkUtils.isAvailable(getApplicationContext(), appInfo.getApp_package()));
|
||||
appInfo.setUpdate(ApkUtils.checkIsUpdate(getApplicationContext(), appInfo.getApp_package(), Integer.parseInt(appInfo.getApp_version_code())));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
@@ -123,4 +117,6 @@ public class KindDetailActivity extends BaseActivity implements RefreshManager.R
|
||||
public void onLoadBitMap(boolean isLoad) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,15 +26,19 @@ import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.appstore.uiui.R;
|
||||
import com.appstore.uiui.base.BaseActivity;
|
||||
import com.appstore.uiui.base.UserInfo;
|
||||
import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.bean.BaseResponse;
|
||||
import com.appstore.uiui.bean.UserInfo;
|
||||
import com.appstore.uiui.fragment.FeaturedFragment;
|
||||
import com.appstore.uiui.fragment.KindFragment;
|
||||
import com.appstore.uiui.fragment.ManageFragment;
|
||||
import com.appstore.uiui.fragment.RankFragment;
|
||||
import com.appstore.uiui.jpush.ExampleUtil;
|
||||
import com.appstore.uiui.jpush.LocalBroadcastManager;
|
||||
import com.appstore.uiui.jpush.TagAliasOperatorHelper;
|
||||
import com.appstore.uiui.network.NetWorkManager;
|
||||
import com.appstore.uiui.network.OKGO;
|
||||
import com.appstore.uiui.network.api.QueryAllApp;
|
||||
import com.appstore.uiui.network.api.SNInfo;
|
||||
import com.appstore.uiui.service.MyDownloadService;
|
||||
import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.LogUtils;
|
||||
@@ -45,10 +49,6 @@ import com.flyco.tablayout.SlidingTabLayout;
|
||||
import com.hjq.permissions.OnPermission;
|
||||
import com.hjq.permissions.Permission;
|
||||
import com.hjq.permissions.XXPermissions;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.FileCallback;
|
||||
import com.lzy.okgo.model.Progress;
|
||||
import com.lzy.okgo.model.Response;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -56,6 +56,10 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import cn.jpush.android.api.JPushInterface;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
import static com.appstore.uiui.jpush.TagAliasOperatorHelper.ACTION_ADD;
|
||||
import static com.appstore.uiui.jpush.TagAliasOperatorHelper.ACTION_CHECK;
|
||||
@@ -78,7 +82,7 @@ public class MainActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.e("MainActivity","onCreate");
|
||||
Log.e("MainActivity", "onCreate");
|
||||
requestPermission();
|
||||
registerMessageReceiver(); // used for receive msg
|
||||
String rid = JPushInterface.getRegistrationID(getApplicationContext());
|
||||
@@ -90,7 +94,9 @@ public class MainActivity extends BaseActivity {
|
||||
// ToastUtil.show("Get registration fail, JPush init failed!");
|
||||
// Toast.makeText(this, "Get registration fail, JPush init failed!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
OKGO.getUserInfo(handler);
|
||||
// OKGO.getUserInfo(handler);
|
||||
getUserInfo();
|
||||
|
||||
// PackageManager pm = getPackageManager();
|
||||
// pm.setApplicationEnabledSetting("com.tencent.qqmusic", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
|
||||
startService(new Intent(MainActivity.this, MyDownloadService.class));
|
||||
@@ -105,12 +111,13 @@ public class MainActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
Log.e("MainActivity","onConfigurationChanged");
|
||||
Log.e("MainActivity", "onConfigurationChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
Log.e("MainActivity","onSaveInstanceState");
|
||||
Log.e("MainActivity", "onSaveInstanceState");
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +153,7 @@ public class MainActivity extends BaseActivity {
|
||||
final List<Fragment> fragmentList = new ArrayList<>();
|
||||
fragmentList.add(new FeaturedFragment());
|
||||
// fragmentList.add(new RankFragment());
|
||||
fragmentList.add(new KindFragment());
|
||||
// fragmentList.add(new KindFragment());
|
||||
fragmentList.add(new ManageFragment());
|
||||
mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
|
||||
@Override
|
||||
@@ -160,13 +167,14 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
mViewPager.setOffscreenPageLimit(3);
|
||||
String titles[] = new String[]{"专属应用", "我的分类", "下载管理"};
|
||||
String titles[] = new String[]{"专属应用",/* "我的分类",*/ "下载管理"};
|
||||
mSlidingTabLayout.setViewPager(mViewPager, titles);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
OKGO.getAllAppPackageName(handler);
|
||||
// OKGO.getAllAppPackageName(handler);
|
||||
getAllAppPackageName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -184,9 +192,9 @@ public class MainActivity extends BaseActivity {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (null != packageInfo) {
|
||||
OKGO.checkUpdateByPackage(handler, packageInfo.packageName, String.valueOf(packageInfo.versionCode));
|
||||
// OKGO.checkUpdateByPackage(handler, packageInfo.packageName, String.valueOf(packageInfo.versionCode));
|
||||
} else {
|
||||
OKGO.checkUpdateByPackage(handler, "com.info.sn", "0");
|
||||
// OKGO.checkUpdateByPackage(handler, "com.info.sn", "0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,27 +393,110 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
synchronized private void getUserInfo() {
|
||||
final SNInfo userInfo = NetWorkManager.getuserInfoControl();
|
||||
userInfo.getUserinfo(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseResponse<UserInfo>>() {
|
||||
@Override
|
||||
public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@io.reactivex.annotations.NonNull BaseResponse<UserInfo> userInfoBaseResponse) {
|
||||
int code = userInfoBaseResponse.code;
|
||||
if (code == 200) {
|
||||
UserInfo info = userInfoBaseResponse.data;
|
||||
SPUtils.put(MainActivity.this, "isLogined", 1);
|
||||
SPUtils.put(MainActivity.this, "admin_id", info.getAdmin_id());
|
||||
SPUtils.put(MainActivity.this, "sn_id", info.getId());
|
||||
SPUtils.put(MainActivity.this, "sn_grade", info.getGrade());
|
||||
} else if (code == -200) {
|
||||
SPUtils.put(MainActivity.this, "isLogined", 0);
|
||||
} else if (code == -250) {
|
||||
SPUtils.put(MainActivity.this, "isLogined", 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.annotations.NonNull Throwable e) {
|
||||
Log.e(TAG, "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void getAllAppPackageName() {
|
||||
QueryAllApp allApp = NetWorkManager.getQueryAllAppControl();
|
||||
allApp.getAllApp(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@io.reactivex.annotations.NonNull BaseResponse<List<AppInfo>> listBaseResponse) {
|
||||
int code = listBaseResponse.code;
|
||||
if (code == 200) {
|
||||
List<AppInfo> infos = listBaseResponse.data;
|
||||
String s = "";
|
||||
for (AppInfo info : infos) {
|
||||
s += info.getApp_package() + ",";
|
||||
}
|
||||
if (s.endsWith(",")) {
|
||||
s = s.substring(0, s.length() - 1);
|
||||
}
|
||||
String qch_app_forbid_before = Settings.System.getString(getContentResolver(), "qch_app_forbid");
|
||||
Log.e("getAllAppPackageName:", "qch_app_forbid_before" + qch_app_forbid_before);
|
||||
boolean qch_app_forbid = Settings.System.putString(getContentResolver(), "qch_app_forbid", s);
|
||||
Log.e("getAllAppPackageName", "qch_app_forbid:" + qch_app_forbid + ":" + s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.annotations.NonNull Throwable e) {
|
||||
Log.e(TAG, "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(@NonNull Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 0:
|
||||
SPUtils.put(MainActivity.this, "isLogined", 0);
|
||||
break;
|
||||
case 1:
|
||||
SPUtils.put(MainActivity.this, "isLogined", 1);
|
||||
UserInfo userInfo = (UserInfo) msg.obj;
|
||||
SPUtils.put(MainActivity.this, "member_id", userInfo.getMember_id());
|
||||
SPUtils.put(MainActivity.this, "sn_id", userInfo.getId());
|
||||
SPUtils.put(MainActivity.this, "sn_grade", userInfo.getSn_grade());
|
||||
break;
|
||||
case 2:
|
||||
SPUtils.put(MainActivity.this, "isLogined", 2);
|
||||
break;
|
||||
// case 0:
|
||||
// SPUtils.put(MainActivity.this, "isLogined", 0);
|
||||
// break;
|
||||
// case 1:
|
||||
// SPUtils.put(MainActivity.this, "isLogined", 1);
|
||||
// UserInfo userInfo = (UserInfo) msg.obj;
|
||||
// SPUtils.put(MainActivity.this, "member_id", userInfo.getMember_id());
|
||||
// SPUtils.put(MainActivity.this, "sn_id", userInfo.getId());
|
||||
// SPUtils.put(MainActivity.this, "sn_grade", userInfo.getGrade());
|
||||
// break;
|
||||
// case 2:
|
||||
// SPUtils.put(MainActivity.this, "isLogined", 2);
|
||||
// break;
|
||||
case 200:
|
||||
String url = (String) msg.obj;
|
||||
getFile(url);
|
||||
// getFile(url);
|
||||
break;
|
||||
case 201:
|
||||
String apppackage = (String) msg.obj;
|
||||
@@ -413,7 +504,6 @@ public class MainActivity extends BaseActivity {
|
||||
if (Settings.System.putString(getContentResolver(), "qch_app_forbid", apppackage)) {
|
||||
Log.e("fht", "app package write successful");
|
||||
}
|
||||
|
||||
break;
|
||||
case 202:
|
||||
break;
|
||||
@@ -421,32 +511,32 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
};
|
||||
|
||||
private void getFile(String url) {
|
||||
OkGo.<File>get(url)
|
||||
.execute(new FileCallback() {
|
||||
@Override
|
||||
public void onSuccess(final Response<File> response) {
|
||||
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApkUtils.installApp(MainActivity.this, response.body().getAbsolutePath());
|
||||
}
|
||||
}).start();
|
||||
LogUtils.e("getFile", "download file successful,now installing");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<File> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("getFile", "File download Failure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadProgress(Progress progress) {
|
||||
super.downloadProgress(progress);
|
||||
LogUtils.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
|
||||
}
|
||||
});
|
||||
}
|
||||
// private void getFile(String url) {
|
||||
// OkGo.<File>get(url)
|
||||
// .execute(new FileCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(final Response<File> response) {
|
||||
//// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
||||
// new Thread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// ApkUtils.installApp(MainActivity.this, response.body().getAbsolutePath());
|
||||
// }
|
||||
// }).start();
|
||||
// LogUtils.e("getFile", "download file successful,now installing");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<File> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("getFile", "File download Failure");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void downloadProgress(Progress progress) {
|
||||
// super.downloadProgress(progress);
|
||||
// LogUtils.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class SearcherActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
madapter = new AppAdapter(mAppInfoList, false, getApplicationContext());
|
||||
madapter = new AppAdapter(mAppInfoList, SearcherActivity.this);
|
||||
madapter.setHasStableIds(true);
|
||||
recyclerView.setAdapter(madapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
@@ -59,7 +59,7 @@ public class SearcherActivity extends BaseActivity {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
LogUtils.e("icon_serach", query);
|
||||
OKGO.searchAppbyName(handler, query);
|
||||
// OKGO.searchAppbyName(handler, query);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -83,18 +83,11 @@ public class SearcherActivity extends BaseActivity {
|
||||
switch (msg.what) {
|
||||
case 1:
|
||||
mAppInfoList = (List<AppInfo>) msg.obj;
|
||||
madapter.setData(checkUpdateOrInstalled(mAppInfoList));
|
||||
madapter.setData(mAppInfoList);
|
||||
madapter.notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public List<AppInfo> checkUpdateOrInstalled(List<AppInfo> list) {
|
||||
for (AppInfo appInfo : list) {
|
||||
appInfo.setInstall(ApkUtils.isAvailable(getApplicationContext(), appInfo.getApp_package()));
|
||||
appInfo.setUpdate(ApkUtils.checkIsUpdate(getApplicationContext(), appInfo.getApp_package(), Integer.parseInt(appInfo.getApp_version_code())));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.appstore.uiui.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -14,20 +12,22 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.appstore.uiui.R;
|
||||
import com.appstore.uiui.activity.DetailsActivity;
|
||||
import com.appstore.uiui.base.FilePath;
|
||||
import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.bean.GlideCircleWithBorder;
|
||||
import com.appstore.uiui.listener.LogDownloadListener;
|
||||
import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.ToastUtil;
|
||||
import com.appstore.uiui.utils.FileUtils;
|
||||
import com.appstore.uiui.utils.StorageUtils;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.model.Progress;
|
||||
import com.lzy.okgo.request.GetRequest;
|
||||
import com.lzy.okserver.OkDownload;
|
||||
import com.lzy.okserver.download.DownloadListener;
|
||||
import com.lzy.okserver.download.DownloadTask;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@@ -39,19 +39,15 @@ import java.util.List;
|
||||
public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
|
||||
|
||||
private List<AppInfo> mAppInfoList;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private boolean isShowOrder;
|
||||
|
||||
private boolean isNotLoadBitmap = false;
|
||||
|
||||
private DownloadTask mDownloadTask;
|
||||
|
||||
//order代表是否显示所在的位置,1.2.3.
|
||||
public AppAdapter(List<AppInfo> appInfoList, boolean isShowOrder, Context context) {
|
||||
|
||||
|
||||
public AppAdapter(List<AppInfo> appInfoList, Context context) {
|
||||
this.mContext = context;
|
||||
this.mAppInfoList = appInfoList;
|
||||
this.isShowOrder = isShowOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,41 +57,18 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(Holder holder, final int position) {
|
||||
|
||||
public void onBindViewHolder(final Holder holder, final int position) {
|
||||
Aria.download(this).register();
|
||||
final AppInfo appInfo = mAppInfoList.get(position);
|
||||
final DownloadTask downloadTask = OkDownload.getInstance().getTask(appInfo.getApp_url());
|
||||
holder.setTag(appInfo.getApp_url());
|
||||
if (downloadTask != null) {
|
||||
downloadTask.register(new ListDownloadListener(appInfo.getApp_url(), holder));
|
||||
holder.setTask(downloadTask);
|
||||
// holder.bind();
|
||||
holder.refresh(downloadTask.progress);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!isNotLoadBitmap) {
|
||||
Glide.with(mContext)
|
||||
.asBitmap()
|
||||
.load(appInfo.getApp_img())
|
||||
.placeholder(R.drawable.ic_place_holder)
|
||||
.transform(new GlideCircleWithBorder(mContext))
|
||||
// .placeholder(R.drawable.ic_place_holder)
|
||||
// .transform(new GlideCircleWithBorder(mContext))
|
||||
.into(holder.ivIcon);
|
||||
} else {
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.ic_place_holder)
|
||||
.transform(new GlideCircleWithBorder(mContext))
|
||||
.into(holder.ivIcon);
|
||||
}
|
||||
|
||||
holder.tvCompany.setText(appInfo.getApp_developer());
|
||||
if (isShowOrder) {
|
||||
holder.tvName.setText((position + 1) + "." + appInfo.getApp_name());
|
||||
} else {
|
||||
holder.tvName.setText(appInfo.getApp_name());
|
||||
}
|
||||
holder.tvSize.setText(appInfo.getApp_size() + "M");
|
||||
holder.tvSize.setText(StorageUtils.byteToMB(appInfo.getApp_size()));
|
||||
holder.ratingBar.setRating((float) appInfo.getApp_score());
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -106,49 +79,83 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
if (appInfo.isInstall()) {
|
||||
if (appInfo.isUpdate()) {
|
||||
final boolean installed = ApkUtils.isInstalled(mContext, appInfo.getApp_package());
|
||||
final boolean update = ApkUtils.isUpdate(mContext, appInfo.getApp_package(), appInfo.getApp_version_code());
|
||||
if (installed) {
|
||||
if (update) {
|
||||
holder.btnDownLoad.setText("更新");
|
||||
holder.btnDownLoad.setTextColor(mContext.getColor(R.color.default_color));
|
||||
holder.btnDownLoad.setBackground(mContext.getDrawable(R.drawable.btn_style_none));
|
||||
holder.btnDownLoad.setBackground(mContext.getDrawable(R.drawable.btn_shap_download));
|
||||
} else {
|
||||
holder.btnDownLoad.setText("打开");
|
||||
holder.btnDownLoad.setTextColor(mContext.getColor(R.color.default_color));
|
||||
holder.btnDownLoad.setBackground(mContext.getDrawable(R.drawable.btn_style_none));
|
||||
holder.btnDownLoad.setBackground(mContext.getDrawable(R.drawable.btn_shap_download));
|
||||
}
|
||||
} else {
|
||||
holder.btnDownLoad.setText("安装");
|
||||
holder.btnDownLoad.setTextColor(mContext.getColor(R.color.default_color));
|
||||
holder.btnDownLoad.setBackground(mContext.getDrawable(R.drawable.btn_style_none));
|
||||
if (downloadTask != null) {
|
||||
holder.refresh(downloadTask.progress);
|
||||
holder.btnDownLoad.setBackground(mContext.getDrawable(R.drawable.btn_shap_download));
|
||||
if (null != mDownloadTask) {
|
||||
if (mDownloadTask.getKey().equals(appInfo.getApp_url())) {
|
||||
holder.refresh(mDownloadTask);
|
||||
}
|
||||
} else {
|
||||
DownloadEntity entity = Aria.download(this).getFirstDownloadEntity(appInfo.getApp_url());
|
||||
if (null != entity) {
|
||||
holder.refreshEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
holder.btnDownLoad.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (appInfo.isInstall() && !appInfo.isUpdate()) {
|
||||
if (installed && !update) {
|
||||
ApkUtils.openApp(mContext, appInfo.getApp_package());
|
||||
} else {
|
||||
downloadApk(appInfo);
|
||||
DownloadEntity entity = Aria.download(this).getFirstDownloadEntity(appInfo.getApp_url());
|
||||
if (null != entity) {
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_OTHER:
|
||||
case IEntity.STATE_FAIL:
|
||||
case IEntity.STATE_STOP:
|
||||
case IEntity.STATE_WAIT:
|
||||
case IEntity.STATE_CANCEL:
|
||||
Aria.download(this).load(entity.getId()).resume();
|
||||
break;
|
||||
case IEntity.STATE_RUNNING:
|
||||
Aria.download(this).load(entity.getId()).stop();
|
||||
break;
|
||||
case IEntity.STATE_PRE:
|
||||
break;
|
||||
case IEntity.STATE_POST_PRE:
|
||||
break;
|
||||
case IEntity.STATE_COMPLETE:
|
||||
File file = new File(entity.getFilePath());
|
||||
if (file.exists()) {
|
||||
holder.btnDownLoad.setText("安装中");
|
||||
ApkUtils.installApp(mContext, entity.getFilePath());
|
||||
} else {
|
||||
Aria.download(this).load(entity.getId()).cancel(true);
|
||||
JSONObject jsonObject = (JSONObject) JSON.toJSON(appInfo);
|
||||
FileUtils.ariaDownload(mContext, appInfo.getApp_url(), jsonObject);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// downloadApk(appInfo);
|
||||
JSONObject jsonObject = (JSONObject) JSON.toJSON(appInfo);
|
||||
FileUtils.ariaDownload(mContext, appInfo.getApp_url(), jsonObject);
|
||||
// Aria.download(this)
|
||||
// .load(appInfo.getApp_url())
|
||||
// .setFilePath(FilePath.FileDownloadPath + File.separator + FileUtils.getFileNamefromURL(appInfo.getApp_url()), true)
|
||||
// .create();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void downloadApk(AppInfo appInfo) {
|
||||
GetRequest<File> request = OkGo.get(appInfo.getApp_url());
|
||||
//这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag
|
||||
OkDownload.request(appInfo.getApp_url(), request)//
|
||||
// .priority(apk.priority)//
|
||||
.extra1(appInfo)//
|
||||
.save()//
|
||||
.register(new LogDownloadListener())//
|
||||
.start();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mAppInfoList == null ? 0 : mAppInfoList.size();
|
||||
@@ -165,10 +172,6 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
|
||||
TextView tvCompany, tvName, tvSize;
|
||||
Button btnDownLoad;
|
||||
RatingBar ratingBar;
|
||||
// TextView tvInstalled;
|
||||
|
||||
private DownloadTask task;
|
||||
private String tag;
|
||||
|
||||
public Holder(View itemView) {
|
||||
super(itemView);
|
||||
@@ -178,54 +181,65 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
|
||||
tvSize = itemView.findViewById(R.id.app_tv_size);
|
||||
btnDownLoad = itemView.findViewById(R.id.app_btn_download);
|
||||
ratingBar = itemView.findViewById(R.id.app_rating_bar);
|
||||
// tvInstalled = itemView.findViewById(R.id.app_tv_installed);
|
||||
}
|
||||
|
||||
public void bind() {
|
||||
|
||||
}
|
||||
|
||||
void refresh(Progress progress) {
|
||||
switch (progress.status) {
|
||||
case Progress.NONE:
|
||||
void refresh(DownloadTask task) {
|
||||
switch (task.getState()) {
|
||||
case IEntity.STATE_OTHER:
|
||||
btnDownLoad.setText("安装");
|
||||
break;
|
||||
case Progress.PAUSE:
|
||||
btnDownLoad.setText("继续");
|
||||
break;
|
||||
case Progress.ERROR:
|
||||
case IEntity.STATE_FAIL:
|
||||
btnDownLoad.setText("出错");
|
||||
break;
|
||||
case Progress.WAITING:
|
||||
case IEntity.STATE_COMPLETE:
|
||||
btnDownLoad.setText("安装");
|
||||
break;
|
||||
case IEntity.STATE_STOP:
|
||||
btnDownLoad.setText("继续");
|
||||
break;
|
||||
case IEntity.STATE_WAIT:
|
||||
btnDownLoad.setText("等待");
|
||||
break;
|
||||
case Progress.FINISH:
|
||||
btnDownLoad.setText("安装中");
|
||||
case IEntity.STATE_RUNNING:
|
||||
btnDownLoad.setText(task.getPercent() + "%");
|
||||
break;
|
||||
case Progress.LOADING:
|
||||
btnDownLoad.setText((int) (progress.fraction * 100) + "%");
|
||||
case IEntity.STATE_PRE:
|
||||
break;
|
||||
case IEntity.STATE_POST_PRE:
|
||||
break;
|
||||
case IEntity.STATE_CANCEL:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setTask(DownloadTask task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
String getTag() {
|
||||
return tag;
|
||||
void refreshEntity(DownloadEntity entity) {
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_OTHER:
|
||||
btnDownLoad.setText("安装");
|
||||
break;
|
||||
case IEntity.STATE_FAIL:
|
||||
btnDownLoad.setText("出错");
|
||||
break;
|
||||
case IEntity.STATE_COMPLETE:
|
||||
btnDownLoad.setText("安装");
|
||||
break;
|
||||
case IEntity.STATE_STOP:
|
||||
btnDownLoad.setText("继续");
|
||||
break;
|
||||
case IEntity.STATE_WAIT:
|
||||
btnDownLoad.setText("等待");
|
||||
break;
|
||||
case IEntity.STATE_RUNNING:
|
||||
btnDownLoad.setText(entity.getPercent() + "%");
|
||||
break;
|
||||
case IEntity.STATE_PRE:
|
||||
break;
|
||||
case IEntity.STATE_POST_PRE:
|
||||
break;
|
||||
case IEntity.STATE_CANCEL:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setNotLoadBitmap(boolean isNotLoadBitmap) {
|
||||
this.isNotLoadBitmap = isNotLoadBitmap;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setData(List<AppInfo> appInfos) {
|
||||
@@ -233,49 +247,105 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private class ListDownloadListener extends DownloadListener {
|
||||
// private class ListDownloadListener extends DownloadListener {
|
||||
//
|
||||
// private Holder holder;
|
||||
//
|
||||
// ListDownloadListener(Object tag, Holder holder) {
|
||||
// super(tag);
|
||||
// this.holder = holder;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onStart(Progress progress) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onProgress(Progress progress) {
|
||||
// if (tag == holder.getTag()) {
|
||||
// holder.refresh(progress);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Progress progress) {
|
||||
// Throwable throwable = progress.exception;
|
||||
// if (throwable != null) throwable.printStackTrace();
|
||||
// ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败,请重试");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFinish(final File file, Progress progress) {
|
||||
// ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成");
|
||||
// new Thread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// ApkUtils.installApp(mContext, file.getAbsolutePath());
|
||||
// }
|
||||
// }).start();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onRemove(Progress progress) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
private Holder holder;
|
||||
|
||||
ListDownloadListener(Object tag, Holder holder) {
|
||||
super(tag);
|
||||
this.holder = holder;
|
||||
private void ItemChanged(DownloadTask task) {
|
||||
mDownloadTask = task;
|
||||
// notifyDataSetChanged();
|
||||
for (int i = 0; i < mAppInfoList.size(); i++) {
|
||||
if (mAppInfoList.get(i).getApp_url().equals(task.getKey())) {
|
||||
notifyItemChanged(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Progress progress) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(Progress progress) {
|
||||
if (tag == holder.getTag()) {
|
||||
holder.refresh(progress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Progress progress) {
|
||||
Throwable throwable = progress.exception;
|
||||
if (throwable != null) throwable.printStackTrace();
|
||||
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败,请重试");
|
||||
@Download.onTaskRunning
|
||||
void onTaskRunning(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(final File file, Progress progress) {
|
||||
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成");
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApkUtils.installApp(mContext, file.getAbsolutePath());
|
||||
}
|
||||
}).start();
|
||||
@Download.onTaskComplete
|
||||
void onTaskComplete(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(Progress progress) {
|
||||
@Download.onWait
|
||||
void onWait(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Download.onTaskStart
|
||||
void onTaskStart(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Download.onPre
|
||||
void onPre(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Download.onTaskResume
|
||||
void onTaskResume(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Download.onTaskStop
|
||||
void onTaskStop(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Download.onTaskCancel
|
||||
void onTaskCancel(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
void onTaskFail(DownloadTask task, Exception e) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,33 +2,32 @@ package com.appstore.uiui.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.text.format.Formatter;
|
||||
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 android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.appstore.uiui.R;
|
||||
import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.bean.GlideCircleWithBorder;
|
||||
import com.appstore.uiui.listener.LogDownloadListener;
|
||||
import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.FileUtils;
|
||||
import com.appstore.uiui.utils.Utils;
|
||||
import com.appstore.uiui.view.NumberProgressBar;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.lzy.okgo.db.DownloadManager;
|
||||
import com.lzy.okgo.model.Progress;
|
||||
import com.lzy.okserver.OkDownload;
|
||||
import com.lzy.okserver.download.DownloadListener;
|
||||
import com.lzy.okserver.download.DownloadTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManagerAdapter.Holder> {
|
||||
@@ -38,8 +37,8 @@ public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManager
|
||||
public static final int TYPE_ING = 2;
|
||||
|
||||
private Context mContext;
|
||||
private List<DownloadTask> values;
|
||||
private int type;
|
||||
private List<DownloadEntity> mEntityList;
|
||||
private DownloadTask mDownloadTask;
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private Handler mhandler;
|
||||
@@ -50,14 +49,25 @@ public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManager
|
||||
this.mhandler = handler;
|
||||
}
|
||||
|
||||
public void updateData(int type) {
|
||||
//这里是将数据库的数据恢复
|
||||
this.type = type;
|
||||
if (type == TYPE_ALL) values = OkDownload.restore(DownloadManager.getInstance().getAll());
|
||||
if (type == TYPE_FINISH)
|
||||
values = OkDownload.restore(DownloadManager.getInstance().getFinished());
|
||||
if (type == TYPE_ING)
|
||||
values = OkDownload.restore(DownloadManager.getInstance().getDownloading());
|
||||
|
||||
// public void updateData(int type) {
|
||||
// //这里是将数据库的数据恢复
|
||||
// this.type = type;
|
||||
// if (type == TYPE_ALL) values = OkDownload.restore(DownloadManager.getInstance().getAll());
|
||||
// if (type == TYPE_FINISH)
|
||||
// values = OkDownload.restore(DownloadManager.getInstance().getFinished());
|
||||
// if (type == TYPE_ING)
|
||||
// values = OkDownload.restore(DownloadManager.getInstance().getDownloading());
|
||||
// notifyDataSetChanged();
|
||||
// }
|
||||
|
||||
public void updateNotCompleteTask() {
|
||||
mEntityList = Aria.download(this).getAllNotCompleteTask();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setData(List<DownloadEntity> list) {
|
||||
this.mEntityList = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -70,40 +80,80 @@ public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManager
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull Holder holder, int position) {
|
||||
DownloadTask task = values.get(position);
|
||||
String tag = createTag(task);
|
||||
task.register(new ListDownloadListener(tag, holder))//
|
||||
.register(new LogDownloadListener());
|
||||
holder.setTag(tag);
|
||||
holder.setTask(task);
|
||||
holder.bind();
|
||||
holder.refresh(task.progress);
|
||||
|
||||
Aria.download(this).register();
|
||||
final DownloadEntity entity = mEntityList.get(position);
|
||||
// DownloadTask task = values.get(position);
|
||||
// String tag = createTag(task);
|
||||
// task.register(new ListDownloadListener(tag, holder))//
|
||||
// .register(new LogDownloadListener());
|
||||
// holder.setTag(tag);
|
||||
// holder.setTask(task);
|
||||
// holder.bind();
|
||||
// holder.refresh(task.progress);
|
||||
JSONObject jsonObject = JSONObject.parseObject(Aria.download(this).load(entity.getId()).getExtendField());
|
||||
Glide.with(mContext)
|
||||
.asBitmap()
|
||||
.load(jsonObject.getString("app_img"))
|
||||
// .placeholder(R.drawable.ic_place_holder)
|
||||
// .transform(new GlideCircleWithBorder(mContext))
|
||||
.into(holder.icon);
|
||||
holder.name.setText(jsonObject.getString("app_name"));
|
||||
holder.pbProgress.setMax(100);
|
||||
holder.pbProgress.setProgress(entity.getPercent());
|
||||
long progress = entity.getCurrentProgress();
|
||||
holder.downloadSize.setText(FileUtils.formatFileSize(progress) + "/" + entity.getConvertFileSize());
|
||||
holder.refreshEntity(entity);
|
||||
holder.start.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_OTHER:
|
||||
case IEntity.STATE_FAIL:
|
||||
case IEntity.STATE_STOP:
|
||||
case IEntity.STATE_WAIT:
|
||||
case IEntity.STATE_CANCEL:
|
||||
Aria.download(this).load(entity.getId()).resume();
|
||||
break;
|
||||
case IEntity.STATE_RUNNING:
|
||||
Aria.download(this).load(entity.getId()).stop();
|
||||
break;
|
||||
case IEntity.STATE_PRE:
|
||||
break;
|
||||
case IEntity.STATE_POST_PRE:
|
||||
break;
|
||||
case IEntity.STATE_COMPLETE:
|
||||
break;
|
||||
}
|
||||
|
||||
public void unRegister() {
|
||||
Map<String, DownloadTask> taskMap = OkDownload.getInstance().getTaskMap();
|
||||
for (DownloadTask task : taskMap.values()) {
|
||||
task.unRegister(createTag(task));
|
||||
}
|
||||
});
|
||||
if (null != mDownloadTask && mDownloadTask.getEntity().getUrl().equals(entity.getUrl())) {
|
||||
holder.refresh(mDownloadTask);
|
||||
}
|
||||
}
|
||||
|
||||
private String createTag(DownloadTask task) {
|
||||
return type + "_" + task.progress.tag;
|
||||
}
|
||||
// public void unRegister() {
|
||||
// Map<String, DownloadTask> taskMap = OkDownload.getInstance().getTaskMap();
|
||||
// for (DownloadTask task : taskMap.values()) {
|
||||
// task.unRegister(createTag(task));
|
||||
// }
|
||||
// }
|
||||
|
||||
// private String createTag(DownloadTask task) {
|
||||
// return type + "_" + task.progress.tag;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return values == null ? 0 : values.size();
|
||||
return null == mEntityList ? 0 : mEntityList.size();
|
||||
}
|
||||
|
||||
class Holder extends RecyclerView.ViewHolder {
|
||||
public class Holder extends RecyclerView.ViewHolder {
|
||||
ImageView icon, remove;
|
||||
TextView name, state, downloadSize;
|
||||
Button start;
|
||||
NumberProgressBar pbProgress;
|
||||
|
||||
private DownloadTask task;
|
||||
// private DownloadTask task;
|
||||
private String tag;
|
||||
|
||||
Holder(@NonNull View itemView) {
|
||||
@@ -117,145 +167,281 @@ public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManager
|
||||
pbProgress = itemView.findViewById(R.id.pbProgress);
|
||||
}
|
||||
|
||||
public void setTask(DownloadTask task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
public void bind() {
|
||||
|
||||
Progress progress = task.progress;
|
||||
AppInfo apk = (AppInfo) progress.extra1;
|
||||
if (apk != null) {
|
||||
Glide.with(mContext)
|
||||
.load(apk.getApp_img())
|
||||
.error(R.mipmap.ic_launcher)
|
||||
.transform(new GlideCircleWithBorder(mContext))
|
||||
.into(icon);
|
||||
name.setText(apk.getApp_name());
|
||||
} else {
|
||||
name.setText(progress.fileName);
|
||||
}
|
||||
start.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
start();
|
||||
}
|
||||
});
|
||||
remove.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
remove();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void refresh(Progress progress) {
|
||||
String currentSize = Formatter.formatFileSize(mContext, progress.currentSize);
|
||||
String totalSize = Formatter.formatFileSize(mContext, progress.totalSize);
|
||||
downloadSize.setText(currentSize + "/" + totalSize);
|
||||
switch (progress.status) {
|
||||
case Progress.NONE:
|
||||
state.setText("停止");
|
||||
void refresh(DownloadTask task) {
|
||||
switch (task.getState()) {
|
||||
case IEntity.STATE_OTHER:
|
||||
start.setText("下载");
|
||||
state.setText("未知");
|
||||
break;
|
||||
case Progress.PAUSE:
|
||||
state.setText("暂停中");
|
||||
case IEntity.STATE_FAIL:
|
||||
start.setText("下载");
|
||||
state.setText("出错");
|
||||
break;
|
||||
case IEntity.STATE_COMPLETE:
|
||||
start.setText("安装中");
|
||||
state.setText("完成");
|
||||
break;
|
||||
case IEntity.STATE_STOP:
|
||||
start.setText("继续");
|
||||
state.setText("停止");
|
||||
break;
|
||||
case Progress.ERROR:
|
||||
state.setText("下载出错");
|
||||
start.setText("出错");
|
||||
break;
|
||||
case Progress.WAITING:
|
||||
state.setText("等待中");
|
||||
case IEntity.STATE_WAIT:
|
||||
start.setText("等待");
|
||||
state.setText("等待");
|
||||
break;
|
||||
case Progress.FINISH:
|
||||
state.setText("下载完成");
|
||||
start.setText("完成");
|
||||
case IEntity.STATE_RUNNING:
|
||||
start.setText(task.getPercent() + "%");
|
||||
pbProgress.setProgress(task.getPercent());
|
||||
state.setText(task.getConvertSpeed());
|
||||
long progress = task.getCurrentProgress();
|
||||
downloadSize.setText(FileUtils.formatFileSize(progress) + "/" + task.getConvertFileSize());
|
||||
break;
|
||||
case Progress.LOADING:
|
||||
String speed = Formatter.formatFileSize(mContext, progress.speed);
|
||||
state.setText(String.format("%s/s", speed));
|
||||
start.setText("暂停");
|
||||
case IEntity.STATE_PRE:
|
||||
break;
|
||||
case IEntity.STATE_POST_PRE:
|
||||
break;
|
||||
case IEntity.STATE_CANCEL:
|
||||
break;
|
||||
}
|
||||
pbProgress.setMax(10000);
|
||||
pbProgress.setProgress((int) (progress.fraction * 10000));
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Progress progress = task.progress;
|
||||
switch (progress.status) {
|
||||
case Progress.PAUSE:
|
||||
case Progress.NONE:
|
||||
case Progress.ERROR:
|
||||
task.start();
|
||||
void refreshEntity(DownloadEntity entity) {
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_OTHER:
|
||||
start.setText("下载");
|
||||
state.setText("未知");
|
||||
break;
|
||||
case Progress.LOADING:
|
||||
task.pause();
|
||||
case IEntity.STATE_FAIL:
|
||||
start.setText("下载");
|
||||
state.setText("出错");
|
||||
break;
|
||||
case Progress.FINISH:
|
||||
|
||||
case IEntity.STATE_COMPLETE:
|
||||
start.setText("安装中");
|
||||
state.setText("完成");
|
||||
break;
|
||||
case IEntity.STATE_STOP:
|
||||
start.setText("继续");
|
||||
state.setText("停止");
|
||||
break;
|
||||
case IEntity.STATE_WAIT:
|
||||
start.setText("等待");
|
||||
state.setText("等待");
|
||||
break;
|
||||
case IEntity.STATE_RUNNING:
|
||||
start.setText(entity.getPercent() + "%");
|
||||
pbProgress.setProgress(entity.getPercent());
|
||||
state.setText("下载中");
|
||||
long progress = entity.getCurrentProgress();
|
||||
downloadSize.setText(FileUtils.formatFileSize(progress) + "/" + entity.getConvertFileSize());
|
||||
break;
|
||||
case IEntity.STATE_PRE:
|
||||
break;
|
||||
case IEntity.STATE_POST_PRE:
|
||||
break;
|
||||
case IEntity.STATE_CANCEL:
|
||||
break;
|
||||
}
|
||||
refresh(progress);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
task.remove(true);
|
||||
updateData(type);
|
||||
|
||||
// public void setTask(DownloadTask task) {
|
||||
// this.task = task;
|
||||
// }
|
||||
|
||||
// public void bind() {
|
||||
// Progress progress = task.progress;
|
||||
// AppInfo apk = (AppInfo) progress.extra1;
|
||||
// if (apk != null) {
|
||||
// Glide.with(mContext)
|
||||
// .load(apk.getApp_img())
|
||||
// .error(R.mipmap.ic_launcher)
|
||||
// .transform(new GlideCircleWithBorder(mContext))
|
||||
// .into(icon);
|
||||
// name.setText(apk.getApp_name());
|
||||
// } else {
|
||||
// name.setText(progress.fileName);
|
||||
// }
|
||||
// start.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// start();
|
||||
// }
|
||||
// });
|
||||
// remove.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// remove();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
|
||||
// public void refresh(Progress progress) {
|
||||
// String currentSize = Formatter.formatFileSize(mContext, progress.currentSize);
|
||||
// String totalSize = Formatter.formatFileSize(mContext, progress.totalSize);
|
||||
// downloadSize.setText(currentSize + "/" + totalSize);
|
||||
// switch (progress.status) {
|
||||
// case Progress.NONE:
|
||||
// state.setText("停止");
|
||||
// start.setText("下载");
|
||||
// break;
|
||||
// case Progress.PAUSE:
|
||||
// state.setText("暂停中");
|
||||
// start.setText("继续");
|
||||
// break;
|
||||
// case Progress.ERROR:
|
||||
// state.setText("下载出错");
|
||||
// start.setText("出错");
|
||||
// break;
|
||||
// case Progress.WAITING:
|
||||
// state.setText("等待中");
|
||||
// start.setText("等待");
|
||||
// break;
|
||||
// case Progress.FINISH:
|
||||
// state.setText("下载完成");
|
||||
// start.setText("完成");
|
||||
// break;
|
||||
// case Progress.LOADING:
|
||||
// String speed = Formatter.formatFileSize(mContext, progress.speed);
|
||||
// state.setText(String.format("%s/s", speed));
|
||||
// start.setText("暂停");
|
||||
// break;
|
||||
// }
|
||||
// pbProgress.setMax(10000);
|
||||
// pbProgress.setProgress((int) (progress.fraction * 10000));
|
||||
// }
|
||||
|
||||
// public void start() {
|
||||
// Progress progress = task.progress;
|
||||
// switch (progress.status) {
|
||||
// case Progress.PAUSE:
|
||||
// case Progress.NONE:
|
||||
// case Progress.ERROR:
|
||||
// task.start();
|
||||
// break;
|
||||
// case Progress.LOADING:
|
||||
// task.pause();
|
||||
// break;
|
||||
// case Progress.FINISH:
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
// refresh(progress);
|
||||
// }
|
||||
//
|
||||
// public void remove() {
|
||||
// task.remove(true);
|
||||
// updateData(type);
|
||||
// }
|
||||
//
|
||||
// public void restart() {
|
||||
// task.restart();
|
||||
// }
|
||||
//
|
||||
// public void setTag(String tag) {
|
||||
// this.tag = tag;
|
||||
// }
|
||||
//
|
||||
// public String getTag() {
|
||||
// return tag;
|
||||
// }
|
||||
}
|
||||
|
||||
public void restart() {
|
||||
task.restart();
|
||||
}
|
||||
// private class ListDownloadListener extends DownloadListener {
|
||||
//
|
||||
// private Holder holder;
|
||||
//
|
||||
// ListDownloadListener(Object tag, Holder holder) {
|
||||
// super(tag);
|
||||
// this.holder = holder;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onStart(Progress progress) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onProgress(Progress progress) {
|
||||
// if (tag == holder.getTag()) {
|
||||
// holder.refresh(progress);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Progress progress) {
|
||||
// Throwable throwable = progress.exception;
|
||||
// if (throwable != null) throwable.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFinish(File file, Progress progress) {
|
||||
// mhandler.sendEmptyMessage(100);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onRemove(Progress progress) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
private void ItemChanged(DownloadTask task) {
|
||||
updateNotCompleteTask();
|
||||
mDownloadTask = task;
|
||||
notifyDataSetChanged();
|
||||
if (null == mEntityList) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < mEntityList.size(); i++) {
|
||||
if (mEntityList.get(i).getUrl().equals(task.getKey())) {
|
||||
notifyItemChanged(i);
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
private class ListDownloadListener extends DownloadListener {
|
||||
|
||||
private Holder holder;
|
||||
|
||||
ListDownloadListener(Object tag, Holder holder) {
|
||||
super(tag);
|
||||
this.holder = holder;
|
||||
@Download.onTaskRunning
|
||||
void onTaskRunning(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Progress progress) {
|
||||
@Download.onTaskComplete
|
||||
void onTaskComplete(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
updateNotCompleteTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(Progress progress) {
|
||||
if (tag == holder.getTag()) {
|
||||
holder.refresh(progress);
|
||||
}
|
||||
@Download.onWait
|
||||
void onWait(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Progress progress) {
|
||||
Throwable throwable = progress.exception;
|
||||
if (throwable != null) throwable.printStackTrace();
|
||||
@Download.onTaskStart
|
||||
void onTaskStart(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(File file, Progress progress) {
|
||||
mhandler.sendEmptyMessage(100);
|
||||
@Download.onPre
|
||||
void onPre(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(Progress progress) {
|
||||
|
||||
}
|
||||
@Download.onTaskResume
|
||||
void onTaskResume(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Download.onTaskStop
|
||||
void onTaskStop(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Download.onTaskCancel
|
||||
void onTaskCancel(DownloadTask task) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
void onTaskFail(DownloadTask task, Exception e) {
|
||||
ItemChanged(task);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import rx.Subscriber;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by asus on 2017/10/26.
|
||||
@@ -65,7 +63,7 @@ public class LocalAppAdapter extends RecyclerView.Adapter<LocalAppAdapter.LocalA
|
||||
holder.btnDownLoad.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ApkUtils.uninstallApp(context, localApp.getPackageName());
|
||||
ApkUtils.Uninstall(context, localApp.getPackageName());
|
||||
}
|
||||
});
|
||||
String totalLength = Formatter.formatFileSize(context, localApp.getSize());
|
||||
|
||||
@@ -11,19 +11,8 @@ import android.widget.TextView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.appstore.uiui.R;
|
||||
import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.bean.UpdateAppInfo;
|
||||
import com.appstore.uiui.listener.LogDownloadListener;
|
||||
import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.ToastUtil;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.model.Progress;
|
||||
import com.lzy.okgo.request.GetRequest;
|
||||
import com.lzy.okserver.OkDownload;
|
||||
import com.lzy.okserver.download.DownloadListener;
|
||||
import com.lzy.okserver.download.DownloadTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.UpdateAppViewHolder> {
|
||||
@@ -45,14 +34,14 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
|
||||
@Override
|
||||
public void onBindViewHolder(UpdateAppViewHolder holder, int position) {
|
||||
final UpdateAppInfo appInfo = localAppList.get(position);
|
||||
final DownloadTask downloadTask = OkDownload.getInstance().getTask(appInfo.getURL());
|
||||
holder.setTag(appInfo.getURL());
|
||||
if (downloadTask != null) {
|
||||
downloadTask.register(new ListDownloadListener(appInfo.getURL(), holder));
|
||||
holder.setTask(downloadTask);
|
||||
// final DownloadTask downloadTask = OkDownload.getInstance().getTask(appInfo.getURL());
|
||||
// holder.setTag(appInfo.getURL());
|
||||
// if (downloadTask != null) {
|
||||
// downloadTask.register(new ListDownloadListener(appInfo.getURL(), holder));
|
||||
// holder.setTask(downloadTask);
|
||||
// holder.bind();
|
||||
holder.refresh(downloadTask.progress);
|
||||
}
|
||||
// holder.refresh(downloadTask.progress);
|
||||
// }
|
||||
|
||||
holder.ivIcon.setImageDrawable(appInfo.getIcon());
|
||||
holder.tvName.setText(appInfo.getAppName());
|
||||
@@ -63,24 +52,24 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
|
||||
holder.btnDownLoad.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
downloadApk(appInfo);
|
||||
// downloadApk(appInfo);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void downloadApk(UpdateAppInfo appInfo) {
|
||||
GetRequest<File> request = OkGo.get(appInfo.getURL());
|
||||
//这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag
|
||||
OkDownload.request(appInfo.getURL(), request)//
|
||||
// .priority(apk.priority)//
|
||||
.extra1(appInfo.getAppInfo())//
|
||||
.save()//
|
||||
.register(new LogDownloadListener())//
|
||||
.start();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
// private void downloadApk(UpdateAppInfo appInfo) {
|
||||
// GetRequest<File> request = OkGo.get(appInfo.getURL());
|
||||
// //这里第一个参数是tag,代表下载任务的唯一标识,传任意字符串都行,需要保证唯一,我这里用url作为了tag
|
||||
// OkDownload.request(appInfo.getURL(), request)//
|
||||
//// .priority(apk.priority)//
|
||||
// .extra1(appInfo.getAppInfo())//
|
||||
// .save()//
|
||||
// .register(new LogDownloadListener())//
|
||||
// .start();
|
||||
// notifyDataSetChanged();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
@@ -98,7 +87,7 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
|
||||
TextView tvUpdate;
|
||||
Button btnDownLoad;
|
||||
|
||||
private DownloadTask task;
|
||||
// private DownloadTask task;
|
||||
private String tag;
|
||||
|
||||
public UpdateAppViewHolder(View itemView) {
|
||||
@@ -114,86 +103,86 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
|
||||
|
||||
}
|
||||
|
||||
void refresh(Progress progress) {
|
||||
switch (progress.status) {
|
||||
case Progress.NONE:
|
||||
btnDownLoad.setText("下载");
|
||||
break;
|
||||
case Progress.PAUSE:
|
||||
btnDownLoad.setText("继续");
|
||||
break;
|
||||
case Progress.ERROR:
|
||||
btnDownLoad.setText("出错");
|
||||
break;
|
||||
case Progress.WAITING:
|
||||
btnDownLoad.setText("等待");
|
||||
break;
|
||||
case Progress.FINISH:
|
||||
btnDownLoad.setText("完成");
|
||||
|
||||
break;
|
||||
case Progress.LOADING:
|
||||
btnDownLoad.setText((int) (progress.fraction * 100) + "%");
|
||||
break;
|
||||
// void refresh(Progress progress) {
|
||||
// switch (progress.status) {
|
||||
// case Progress.NONE:
|
||||
// btnDownLoad.setText("下载");
|
||||
// break;
|
||||
// case Progress.PAUSE:
|
||||
// btnDownLoad.setText("继续");
|
||||
// break;
|
||||
// case Progress.ERROR:
|
||||
// btnDownLoad.setText("出错");
|
||||
// break;
|
||||
// case Progress.WAITING:
|
||||
// btnDownLoad.setText("等待");
|
||||
// break;
|
||||
// case Progress.FINISH:
|
||||
// btnDownLoad.setText("完成");
|
||||
//
|
||||
// break;
|
||||
// case Progress.LOADING:
|
||||
// btnDownLoad.setText((int) (progress.fraction * 100) + "%");
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// void setTask(DownloadTask task) {
|
||||
// this.task = task;
|
||||
// }
|
||||
//
|
||||
// void setTag(String tag) {
|
||||
// this.tag = tag;
|
||||
// }
|
||||
//
|
||||
// String getTag() {
|
||||
// return tag;
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setTask(DownloadTask task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
String getTag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
private class ListDownloadListener extends DownloadListener {
|
||||
|
||||
private UpdateAppViewHolder holder;
|
||||
|
||||
ListDownloadListener(Object tag, UpdateAppViewHolder holder) {
|
||||
super(tag);
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Progress progress) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(Progress progress) {
|
||||
if (tag == holder.getTag()) {
|
||||
holder.refresh(progress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Progress progress) {
|
||||
Throwable throwable = progress.exception;
|
||||
if (throwable != null) throwable.printStackTrace();
|
||||
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败,请重试");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(final File file, Progress progress) {
|
||||
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成");
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApkUtils.installApp(context,file.getAbsolutePath() );
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(Progress progress) {
|
||||
}
|
||||
}
|
||||
// private class ListDownloadListener extends DownloadListener {
|
||||
//
|
||||
// private UpdateAppViewHolder holder;
|
||||
//
|
||||
// ListDownloadListener(Object tag, UpdateAppViewHolder holder) {
|
||||
// super(tag);
|
||||
// this.holder = holder;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onStart(Progress progress) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onProgress(Progress progress) {
|
||||
// if (tag == holder.getTag()) {
|
||||
// holder.refresh(progress);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Progress progress) {
|
||||
// Throwable throwable = progress.exception;
|
||||
// if (throwable != null) throwable.printStackTrace();
|
||||
// ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败,请重试");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFinish(final File file, Progress progress) {
|
||||
// ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成");
|
||||
// new Thread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// ApkUtils.installApp(context,file.getAbsolutePath() );
|
||||
// }
|
||||
// }).start();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onRemove(Progress progress) {
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
8
app/src/main/java/com/appstore/uiui/base/FilePath.java
Normal file
8
app/src/main/java/com/appstore/uiui/base/FilePath.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.appstore.uiui.base;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
public class FilePath {
|
||||
public static final String FileDownloadPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();
|
||||
|
||||
}
|
||||
@@ -40,6 +40,7 @@ public abstract class LazyLoadFragment extends Fragment {
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(getLayoutId(), container, false);
|
||||
initViews(view);
|
||||
initDatas();
|
||||
isViewCreated = true;
|
||||
return view;
|
||||
}
|
||||
@@ -47,6 +48,7 @@ public abstract class LazyLoadFragment extends Fragment {
|
||||
public abstract int getLayoutId();
|
||||
|
||||
public abstract void initViews(View view);
|
||||
public abstract void initDatas();
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
|
||||
@@ -7,8 +7,8 @@ public class AppInfo implements Serializable {
|
||||
private String app_name;
|
||||
private String app_package;
|
||||
private String app_version_name;
|
||||
private String app_version_code;
|
||||
private String app_size;
|
||||
private int app_version_code;
|
||||
private long app_size;
|
||||
private String app_desc;
|
||||
private String app_url;
|
||||
private String app_img;
|
||||
@@ -25,12 +25,9 @@ public class AppInfo implements Serializable {
|
||||
private int is_delete;
|
||||
private int is_update;
|
||||
private int is_silent;
|
||||
private String app_md5;
|
||||
private String createtime;
|
||||
|
||||
private boolean isInstall = false;
|
||||
private boolean isUpdate = false;
|
||||
|
||||
|
||||
public int getApp_id() {
|
||||
return app_id;
|
||||
}
|
||||
@@ -63,19 +60,19 @@ public class AppInfo implements Serializable {
|
||||
this.app_version_name = app_version_name;
|
||||
}
|
||||
|
||||
public String getApp_version_code() {
|
||||
public int getApp_version_code() {
|
||||
return app_version_code;
|
||||
}
|
||||
|
||||
public void setApp_version_code(String app_version_code) {
|
||||
public void setApp_version_code(int app_version_code) {
|
||||
this.app_version_code = app_version_code;
|
||||
}
|
||||
|
||||
public String getApp_size() {
|
||||
public long getApp_size() {
|
||||
return app_size;
|
||||
}
|
||||
|
||||
public void setApp_size(String app_size) {
|
||||
public void setApp_size(long app_size) {
|
||||
this.app_size = app_size;
|
||||
}
|
||||
|
||||
@@ -215,19 +212,11 @@ public class AppInfo implements Serializable {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public void setInstall(boolean b) {
|
||||
this.isInstall = b;
|
||||
public String getApp_md5() {
|
||||
return app_md5;
|
||||
}
|
||||
|
||||
public boolean isInstall() {
|
||||
return isInstall;
|
||||
}
|
||||
|
||||
public boolean isUpdate() {
|
||||
return isUpdate;
|
||||
}
|
||||
|
||||
public void setUpdate(boolean b) {
|
||||
this.isUpdate = b;
|
||||
public void setApp_md5(String app_md5) {
|
||||
this.app_md5 = app_md5;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
package com.appstore.uiui.bean;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BaseResponse implements Serializable {
|
||||
|
||||
public class BaseResponse<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5468533687801294972L;
|
||||
|
||||
public int code;
|
||||
public String data;
|
||||
public String msg;
|
||||
public T data;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{\n" +//
|
||||
"\tcode=" + code + "\n" +//
|
||||
"\tmsg='" + msg + "\'\n" +//
|
||||
"\tdata=" + data + "\n" +//
|
||||
'}';
|
||||
}
|
||||
}
|
||||
13
app/src/main/java/com/appstore/uiui/bean/ImageUrl.java
Normal file
13
app/src/main/java/com/appstore/uiui/bean/ImageUrl.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.appstore.uiui.bean;
|
||||
|
||||
public class ImageUrl {
|
||||
String img_url;
|
||||
|
||||
public String getImg_url() {
|
||||
return img_url;
|
||||
}
|
||||
|
||||
public void setImg_url(String img_url) {
|
||||
this.img_url = img_url;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,30 @@
|
||||
package com.appstore.uiui.base;
|
||||
package com.appstore.uiui.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class UserInfo implements Serializable {
|
||||
private String id;
|
||||
|
||||
private static final long serialVersionUID = -5268233433601073239L;
|
||||
|
||||
private int id;
|
||||
private String sn_value;
|
||||
private String sn_name;
|
||||
private String sn_phone;
|
||||
private String sn_school;
|
||||
private int sn_grade;
|
||||
private String grade;
|
||||
private String sn_app;
|
||||
private String sn_area;
|
||||
private int member_id;
|
||||
private int is_delete;
|
||||
private int is_reset;
|
||||
private int is_lock;
|
||||
private int admin_id;
|
||||
private String is_delete;
|
||||
private String is_reset;
|
||||
private String is_lock;
|
||||
private String school;
|
||||
private String createtime;
|
||||
|
||||
public String getId() {
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -49,20 +52,12 @@ public class UserInfo implements Serializable {
|
||||
this.sn_phone = sn_phone;
|
||||
}
|
||||
|
||||
public String getSn_school() {
|
||||
return sn_school;
|
||||
public String getGrade() {
|
||||
return grade;
|
||||
}
|
||||
|
||||
public void setSn_school(String sn_school) {
|
||||
this.sn_school = sn_school;
|
||||
}
|
||||
|
||||
public int getSn_grade() {
|
||||
return sn_grade;
|
||||
}
|
||||
|
||||
public void setSn_grade(int sn_grade) {
|
||||
this.sn_grade = sn_grade;
|
||||
public void setGrade(String grade) {
|
||||
this.grade = grade;
|
||||
}
|
||||
|
||||
public String getSn_app() {
|
||||
@@ -81,35 +76,35 @@ public class UserInfo implements Serializable {
|
||||
this.sn_area = sn_area;
|
||||
}
|
||||
|
||||
public int getMember_id() {
|
||||
return member_id;
|
||||
public int getAdmin_id() {
|
||||
return admin_id;
|
||||
}
|
||||
|
||||
public void setMember_id(int member_id) {
|
||||
this.member_id = member_id;
|
||||
public void setAdmin_id(int admin_id) {
|
||||
this.admin_id = admin_id;
|
||||
}
|
||||
|
||||
public int getIs_delete() {
|
||||
public String getIs_delete() {
|
||||
return is_delete;
|
||||
}
|
||||
|
||||
public void setIs_delete(int is_delete) {
|
||||
public void setIs_delete(String is_delete) {
|
||||
this.is_delete = is_delete;
|
||||
}
|
||||
|
||||
public int getIs_reset() {
|
||||
public String getIs_reset() {
|
||||
return is_reset;
|
||||
}
|
||||
|
||||
public void setIs_reset(int is_reset) {
|
||||
public void setIs_reset(String is_reset) {
|
||||
this.is_reset = is_reset;
|
||||
}
|
||||
|
||||
public int getIs_lock() {
|
||||
public String getIs_lock() {
|
||||
return is_lock;
|
||||
}
|
||||
|
||||
public void setIs_lock(int is_lock) {
|
||||
public void setIs_lock(String is_lock) {
|
||||
this.is_lock = is_lock;
|
||||
}
|
||||
|
||||
@@ -120,4 +115,12 @@ public class UserInfo implements Serializable {
|
||||
public void setCreatetime(String createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public String getSchool() {
|
||||
return school;
|
||||
}
|
||||
|
||||
public void setSchool(String school) {
|
||||
this.school = school;
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,14 @@ import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
|
||||
import com.appstore.uiui.R;
|
||||
import com.appstore.uiui.adapter.AppAdapter;
|
||||
@@ -22,10 +24,15 @@ import com.appstore.uiui.base.LazyLoadFragment;
|
||||
import com.appstore.uiui.base.RefreshManager;
|
||||
import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.bean.AppInfos;
|
||||
import com.appstore.uiui.bean.BaseResponse;
|
||||
import com.appstore.uiui.bean.ImageUrl;
|
||||
import com.appstore.uiui.network.NetWorkManager;
|
||||
import com.appstore.uiui.network.OKGO;
|
||||
import com.appstore.uiui.network.api.BannerImage;
|
||||
import com.appstore.uiui.network.api.QueryAllApp;
|
||||
import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.LogUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.appstore.uiui.utils.Utils;
|
||||
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
||||
import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
||||
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
|
||||
@@ -39,6 +46,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
/**
|
||||
* Created by asus on 2017/10/23.
|
||||
@@ -58,6 +71,7 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
|
||||
private installReceiver myReceiver;
|
||||
private Context mContext;
|
||||
private String TAG = "FeaturedFragment";
|
||||
|
||||
public FeaturedFragment() {
|
||||
|
||||
@@ -71,9 +85,15 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (myReceiver != null) {
|
||||
try {
|
||||
mContext.unregisterReceiver(myReceiver);
|
||||
getActivity().unregisterReceiver(myReceiver);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("onStop", e.getMessage());
|
||||
}
|
||||
@@ -81,10 +101,9 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
public void initDatas() {
|
||||
mContext = this.getActivity();
|
||||
adapter = new AppAdapter(newAppInfoList, false, getContext());
|
||||
adapter = new AppAdapter(newAppInfoList, getActivity());
|
||||
adapter.setHasStableIds(true);
|
||||
int orientation = 0;
|
||||
orientation = mContext.getResources().getConfiguration().orientation;
|
||||
@@ -109,30 +128,39 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
});
|
||||
mRefreshLayout.autoRefresh();
|
||||
|
||||
adapter.setData(checkUpdateOrInstalled(newAppInfoList));
|
||||
adapter.setData(newAppInfoList);
|
||||
adapter.notifyDataSetChanged();
|
||||
if (myReceiver == null) {
|
||||
myReceiver = new installReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("com.appstore.uiui.PACKAGE_ADDED");
|
||||
filter.addAction("com.appstore.uiui.PACKAGE_REPLACED");
|
||||
filter.addAction("com.appstore.uiui.PACKAGE_REMOVED");
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
mContext.registerReceiver(myReceiver, filter);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
if (myReceiver == null) {
|
||||
myReceiver = new installReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||
filter.addDataScheme("package");
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
getActivity().registerReceiver(myReceiver, filter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews(View view) {
|
||||
mRvResult = view.findViewById(R.id.featured_rv_result);
|
||||
((SimpleItemAnimator) mRvResult.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||
// mRvResult.setItemAnimator(null);
|
||||
imageView = view.findViewById(R.id.imageView);
|
||||
mRefreshLayout = view.findViewById(R.id.featured_refresh_layout);
|
||||
RefreshManager.getInstance().register(this);
|
||||
@@ -149,14 +177,13 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
.setOnPageClickListener(new BannerViewPager.OnPageClickListener() {
|
||||
@Override
|
||||
public void onPageClick(int position) {
|
||||
ToastUtils.showShort("position:" + position);
|
||||
|
||||
}
|
||||
})
|
||||
.setInterval(5000);
|
||||
isNotLoadBitmap = false;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,8 +193,10 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
}
|
||||
|
||||
synchronized private void initAPPData(final Handler handler) {
|
||||
OKGO.getAllAppInfo(handler);
|
||||
OKGO.getBannerImg(handler);
|
||||
// OKGO.getAllAppInfo(handler);
|
||||
getAllAppInfo();
|
||||
// OKGO.getBannerImg(handler);
|
||||
getBannerImg();
|
||||
}
|
||||
|
||||
|
||||
@@ -178,7 +207,102 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
|
||||
@Override
|
||||
public void onLoadBitMap(boolean isLoad) {
|
||||
adapter.setNotLoadBitmap(isLoad);
|
||||
}
|
||||
|
||||
|
||||
private void getAllAppInfo() {
|
||||
QueryAllApp allApp = NetWorkManager.getQueryAllAppControl();
|
||||
allApp.getAllApp(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<AppInfo>> listBaseResponse) {
|
||||
int code = listBaseResponse.code;
|
||||
if (code == 200) {
|
||||
List<AppInfo> infos = listBaseResponse.data;
|
||||
newAppInfoList = infos;
|
||||
mRvResult.setVisibility(View.VISIBLE);
|
||||
imageView.setVisibility(View.GONE);
|
||||
adapter.setData(newAppInfoList);
|
||||
adapter.notifyDataSetChanged();
|
||||
} else {
|
||||
mRvResult.setVisibility(View.GONE);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAllAppInfo", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
mRefreshLayout.finishRefresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getBannerImg() {
|
||||
BannerImage bannerImage = NetWorkManager.getBannerImageControl();
|
||||
bannerImage.getImageURL(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseResponse<List<ImageUrl>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<ImageUrl>> listBaseResponse) {
|
||||
int code = listBaseResponse.code;
|
||||
if (code == 200) {
|
||||
List<ImageUrl> urlList = listBaseResponse.data;
|
||||
if (null != urlList || urlList.size() != 0) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (ImageUrl url : urlList) {
|
||||
list.add(url.getImg_url());
|
||||
}
|
||||
mViewPager
|
||||
.setPageMargin(getResources().getDimensionPixelOffset(R.dimen.dp_5))
|
||||
.setRevealWidth(BannerUtils.dp2px(0))
|
||||
.setPageStyle(PageStyle.MULTI_PAGE)
|
||||
.setHolderCreator(new HolderCreator<BannerViewHolder>() {
|
||||
@Override
|
||||
public BannerViewHolder createViewHolder() {
|
||||
return new BannerViewHolder();
|
||||
}
|
||||
})
|
||||
.setIndicatorColor(getResources().getColor(R.color.white), getResources().getColor(R.color.colorAccent))
|
||||
.setOnPageClickListener(new BannerViewPager.OnPageClickListener() {
|
||||
@Override
|
||||
public void onPageClick(int position) {
|
||||
|
||||
}
|
||||
})
|
||||
.setInterval(5000)
|
||||
.create(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getBannerImg", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
mRefreshLayout.finishRefresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Handler handler = new Handler() {
|
||||
@@ -186,17 +310,17 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 0:
|
||||
mRvResult.setVisibility(View.GONE);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case 1:
|
||||
mRvResult.setVisibility(View.VISIBLE);
|
||||
imageView.setVisibility(View.GONE);
|
||||
newAppInfoList = (List<AppInfo>) msg.obj;
|
||||
adapter.setData(checkUpdateOrInstalled(newAppInfoList));
|
||||
adapter.notifyDataSetChanged();
|
||||
break;
|
||||
// case 0:
|
||||
// mRvResult.setVisibility(View.GONE);
|
||||
// imageView.setVisibility(View.VISIBLE);
|
||||
// break;
|
||||
// case 1:
|
||||
// mRvResult.setVisibility(View.VISIBLE);
|
||||
// imageView.setVisibility(View.GONE);
|
||||
// newAppInfoList = (List<AppInfo>) msg.obj;
|
||||
// adapter.setData(checkUpdateOrInstalled(newAppInfoList));
|
||||
// adapter.notifyDataSetChanged();
|
||||
// break;
|
||||
case 200:
|
||||
List<String> list = (List<String>) msg.obj;
|
||||
mViewPager
|
||||
@@ -213,7 +337,7 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
.setOnPageClickListener(new BannerViewPager.OnPageClickListener() {
|
||||
@Override
|
||||
public void onPageClick(int position) {
|
||||
ToastUtils.showShort("position:" + position);
|
||||
|
||||
}
|
||||
})
|
||||
.setInterval(5000)
|
||||
@@ -224,22 +348,25 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
}
|
||||
};
|
||||
|
||||
public List<AppInfo> checkUpdateOrInstalled(List<AppInfo> list) {
|
||||
for (AppInfo appInfo : list) {
|
||||
appInfo.setInstall(ApkUtils.isAvailable(mContext, appInfo.getApp_package()));
|
||||
appInfo.setUpdate(ApkUtils.checkIsUpdate(mContext, appInfo.getApp_package(), Integer.parseInt(appInfo.getApp_version_code())));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
// public List<AppInfo> checkUpdateOrInstalled(List<AppInfo> list) {
|
||||
// for (AppInfo appInfo : list) {
|
||||
// appInfo.setInstall(ApkUtils.isAvailable(mContext, appInfo.getApp_package()));
|
||||
// appInfo.setUpdate(ApkUtils.checkIsUpdate(mContext, appInfo.getApp_package(), Integer.parseInt(appInfo.getApp_version_code())));
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
|
||||
public class installReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
//接收安装广播
|
||||
if (action.equals("com.appstore.uiui.PACKAGE_ADDED") || action.equals("com.appstore.uiui.PACKAGE_REMOVED") || action.equals("com.appstore.uiui.PACKAGE_REPLACED")) {
|
||||
adapter.setData(checkUpdateOrInstalled(newAppInfoList));
|
||||
if (action.equals(Intent.ACTION_PACKAGE_ADDED)
|
||||
|| action.equals(Intent.ACTION_PACKAGE_REPLACED)
|
||||
|| action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
|
||||
// adapter.setData(checkUpdateOrInstalled(newAppInfoList));
|
||||
adapter.notifyDataSetChanged();
|
||||
Log.e("installReceiver", action);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.appstore.uiui.base.BaseFragment;
|
||||
import com.appstore.uiui.base.RefreshManager;
|
||||
import com.appstore.uiui.bean.Kind;
|
||||
import com.appstore.uiui.network.OKGO;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
||||
import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
||||
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
|
||||
@@ -80,7 +79,7 @@ public class KindFragment extends BaseFragment implements RefreshManager.Refresh
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
OKGO.getSubClassfy(mHandler);
|
||||
// OKGO.getSubClassfy(mHandler);
|
||||
}
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
|
||||
@@ -85,6 +85,11 @@ public class ManageFragment extends LazyLoadFragment {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initDatas() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData(Bundle savedInstanceState) {
|
||||
|
||||
@@ -98,7 +103,7 @@ public class ManageFragment extends LazyLoadFragment {
|
||||
}
|
||||
|
||||
synchronized private void initAPPData(final Handler handler) {
|
||||
OKGO.getAllAppInfo(handler);
|
||||
// OKGO.getAllAppInfo(handler);
|
||||
}
|
||||
|
||||
synchronized private List<LocalApp> getLocalApp() {
|
||||
@@ -147,13 +152,13 @@ public class ManageFragment extends LazyLoadFragment {
|
||||
for (LocalApp app : localAppList) {
|
||||
if (packageNameList.contains(app.getPackageName())) {
|
||||
AppInfo info = list.get(packageNameList.indexOf(app.getPackageName()));
|
||||
if (ApkUtils.checkIsUpdate(mContext, info.getApp_package(), Integer.parseInt(info.getApp_version_code()))) {
|
||||
if (ApkUtils.checkIsUpdate(mContext, info.getApp_package(), info.getApp_version_code())) {
|
||||
UpdateAppInfo updateAppInfo = new UpdateAppInfo();
|
||||
updateAppInfo.setVersionCode(app.getVersionCode());
|
||||
updateAppInfo.setVersionName(app.getVersion());
|
||||
updateAppInfo.setAppName(app.getAppName());
|
||||
updateAppInfo.setIcon(app.getIcon());
|
||||
updateAppInfo.setNewVersionCode(Integer.parseInt(info.getApp_version_code()));
|
||||
updateAppInfo.setNewVersionCode(info.getApp_version_code());
|
||||
updateAppInfo.setNewVersionName(info.getApp_version_name());
|
||||
updateAppInfo.setURL(info.getApp_url());
|
||||
updateAppInfo.setPackageName(info.getApp_package());
|
||||
|
||||
@@ -51,6 +51,11 @@ public class RankFragment extends LazyLoadFragment implements RefreshManager.Ref
|
||||
initView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initDatas() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData(Bundle savedInstanceState) {
|
||||
|
||||
@@ -59,7 +64,7 @@ public class RankFragment extends LazyLoadFragment implements RefreshManager.Ref
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
OKGO.getRankApp(handler);
|
||||
// OKGO.getRankApp(handler);
|
||||
LogUtils.e("fht", "RankFragment onStart");
|
||||
}
|
||||
|
||||
@@ -93,7 +98,7 @@ public class RankFragment extends LazyLoadFragment implements RefreshManager.Ref
|
||||
|
||||
private void initView() {
|
||||
mAppInfoList = new ArrayList<>();
|
||||
mAppAdapter = new AppAdapter(mAppInfoList, true, getContext());
|
||||
mAppAdapter = new AppAdapter(mAppInfoList, getActivity());
|
||||
mRvResult.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
mRvResult.setAdapter(mAppAdapter);
|
||||
mRefreshLayout.setEnableRefresh(true);
|
||||
@@ -101,7 +106,7 @@ public class RankFragment extends LazyLoadFragment implements RefreshManager.Ref
|
||||
mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh(RefreshLayout refreshlayout) {
|
||||
OKGO.getRankApp(handler);
|
||||
// OKGO.getRankApp(handler);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -124,7 +129,7 @@ public class RankFragment extends LazyLoadFragment implements RefreshManager.Ref
|
||||
switch (msg.what) {
|
||||
case 1:
|
||||
mAppInfoList = (List<AppInfo>) msg.obj;
|
||||
mAppAdapter.setData(checkUpdateOrInstalled(mAppInfoList));
|
||||
mAppAdapter.setData(mAppInfoList);
|
||||
mAppAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
@@ -132,11 +137,4 @@ public class RankFragment extends LazyLoadFragment implements RefreshManager.Ref
|
||||
}
|
||||
};
|
||||
|
||||
public List<AppInfo> checkUpdateOrInstalled(List<AppInfo> list) {
|
||||
for (AppInfo appInfo : list) {
|
||||
appInfo.setInstall(ApkUtils.isAvailable(getContext(), appInfo.getApp_package()));
|
||||
appInfo.setUpdate(ApkUtils.checkIsUpdate(getContext(), appInfo.getApp_package(), Integer.parseInt(appInfo.getApp_version_code())));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 jeasonlzy(廖子尧)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.appstore.uiui.listener;
|
||||
|
||||
import com.lzy.okgo.model.Progress;
|
||||
import com.lzy.okserver.download.DownloadListener;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* ================================================
|
||||
* 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy
|
||||
* 版 本:1.0
|
||||
* 创建日期:2017/6/7
|
||||
* 描 述:
|
||||
* 修订历史:
|
||||
* ================================================
|
||||
*/
|
||||
public class LogDownloadListener extends DownloadListener {
|
||||
|
||||
public LogDownloadListener() {
|
||||
super("LogDownloadListener");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Progress progress) {
|
||||
System.out.println("onStart: " + progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(Progress progress) {
|
||||
System.out.println("onProgress: " + progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Progress progress) {
|
||||
System.out.println("onError: " + progress);
|
||||
progress.exception.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(File file, Progress progress) {
|
||||
System.out.println("onFinish: " + progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(Progress progress) {
|
||||
System.out.println("onRemove: " + progress);
|
||||
}
|
||||
}
|
||||
103
app/src/main/java/com/appstore/uiui/network/NetWorkManager.java
Normal file
103
app/src/main/java/com/appstore/uiui/network/NetWorkManager.java
Normal file
@@ -0,0 +1,103 @@
|
||||
package com.appstore.uiui.network;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
import com.appstore.uiui.network.URLs.UrlAddress;
|
||||
import com.appstore.uiui.network.api.BannerImage;
|
||||
import com.appstore.uiui.network.api.DownloadApp;
|
||||
import com.appstore.uiui.network.api.QueryAllApp;
|
||||
import com.appstore.uiui.network.api.SNInfo;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import retrofit2.CallAdapter;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class NetWorkManager {
|
||||
|
||||
private static final String ROOT_URL = UrlAddress.ROOT_URL;
|
||||
|
||||
private static final long cacheSize = 1024 * 1024 * 20;// 缓存文件最大限制大小20M
|
||||
private static String cacheDirectory = Environment.getExternalStorageDirectory() + "/okttpcaches"; // 设置缓存文件路径
|
||||
private static Cache cache = new Cache(new File(cacheDirectory), cacheSize); //
|
||||
private static final OkHttpClient client;
|
||||
|
||||
static {
|
||||
//如果无法生存缓存文件目录,检测权限使用已经加上,检测手机是否把文件读写权限禁止了
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
builder.connectTimeout(8, TimeUnit.SECONDS); // 设置连接超时时间
|
||||
builder.writeTimeout(8, TimeUnit.SECONDS);// 设置写入超时时间
|
||||
builder.readTimeout(8, TimeUnit.SECONDS);// 设置读取数据超时时间
|
||||
builder.retryOnConnectionFailure(true);// 设置进行连接失败重试
|
||||
builder.cache(cache);// 设置缓存
|
||||
client = builder.build();
|
||||
}
|
||||
|
||||
private static CallAdapter.Factory rxJavaCallAdapterFactory = RxJava2CallAdapterFactory.create();
|
||||
private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();
|
||||
|
||||
private static SNInfo userInfoControl;
|
||||
private static QueryAllApp queryAllAppControl;
|
||||
private static BannerImage bannerImageControl;
|
||||
private static DownloadApp downloadAppControl;
|
||||
|
||||
|
||||
public static SNInfo getuserInfoControl() {
|
||||
if (null == userInfoControl) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.client(client)
|
||||
.baseUrl(ROOT_URL)
|
||||
.addConverterFactory(gsonConverterFactory)
|
||||
.addCallAdapterFactory(rxJavaCallAdapterFactory)
|
||||
.build();
|
||||
userInfoControl = retrofit.create(SNInfo.class);
|
||||
}
|
||||
return userInfoControl;
|
||||
}
|
||||
|
||||
public static QueryAllApp getQueryAllAppControl() {
|
||||
if (null == queryAllAppControl) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.client(client)
|
||||
.baseUrl(ROOT_URL)
|
||||
.addConverterFactory(gsonConverterFactory)
|
||||
.addCallAdapterFactory(rxJavaCallAdapterFactory)
|
||||
.build();
|
||||
queryAllAppControl = retrofit.create(QueryAllApp.class);
|
||||
}
|
||||
return queryAllAppControl;
|
||||
}
|
||||
|
||||
public static BannerImage getBannerImageControl() {
|
||||
if (null == bannerImageControl) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.client(client)
|
||||
.baseUrl(ROOT_URL)
|
||||
.addConverterFactory(gsonConverterFactory)
|
||||
.addCallAdapterFactory(rxJavaCallAdapterFactory)
|
||||
.build();
|
||||
bannerImageControl = retrofit.create(BannerImage.class);
|
||||
}
|
||||
return bannerImageControl;
|
||||
}
|
||||
|
||||
public static DownloadApp getDownloadAppControl() {
|
||||
if (null == downloadAppControl) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.client(client)
|
||||
.baseUrl(ROOT_URL)
|
||||
.addConverterFactory(gsonConverterFactory)
|
||||
.addCallAdapterFactory(rxJavaCallAdapterFactory)
|
||||
.build();
|
||||
downloadAppControl = retrofit.create(DownloadApp.class);
|
||||
}
|
||||
return downloadAppControl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,24 +10,23 @@ import androidx.annotation.NonNull;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.appstore.uiui.TextCode.MessageWhat;
|
||||
import com.appstore.uiui.base.UserInfo;
|
||||
import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.bean.BaseResponse;
|
||||
import com.appstore.uiui.bean.bannerImage;
|
||||
import com.appstore.uiui.network.URLs.Url;
|
||||
import com.appstore.uiui.network.URLs.UrlAddress;
|
||||
import com.appstore.uiui.network.api.SNInfo;
|
||||
import com.appstore.uiui.utils.LogUtils;
|
||||
import com.appstore.uiui.utils.SPUtils;
|
||||
import com.appstore.uiui.utils.ToastUtil;
|
||||
import com.appstore.uiui.utils.Utils;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.StringCallback;
|
||||
import com.lzy.okgo.model.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.internal.Util;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
public class OKGO {
|
||||
@@ -35,480 +34,480 @@ public class OKGO {
|
||||
private static final int GET_USERINFO = 1;
|
||||
private static final int GET_SORTAPP = 2;
|
||||
|
||||
private Handler mhandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(@NonNull Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case GET_ALL_APPINFO:
|
||||
break;
|
||||
case GET_USERINFO:
|
||||
// private Handler mhandler = new Handler() {
|
||||
// @Override
|
||||
// public void handleMessage(@NonNull Message msg) {
|
||||
// super.handleMessage(msg);
|
||||
// switch (msg.what) {
|
||||
// case GET_ALL_APPINFO:
|
||||
// break;
|
||||
// case GET_USERINFO:
|
||||
//
|
||||
// break;
|
||||
// case GET_SORTAPP:
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
break;
|
||||
case GET_SORTAPP:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
synchronized public static void getAllAppInfo(final Handler handler) {
|
||||
OkGo.<String>post(Url.GET_ALL_APPINFO)
|
||||
.params("sn", Utils.getSerial())
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
try {
|
||||
JSONObject body = JSON.parseObject(response.body());
|
||||
// synchronized public static void getAllAppInfo(final Handler handler) {
|
||||
// OkGo.<String>post(UrlAddress.GET_ALL_APPINFO)
|
||||
// .params("sn", Utils.getSerial())
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// try {
|
||||
// JSONObject body = JSON.parseObject(response.body());
|
||||
//// LogUtils.e("onSuccess", body.toString());
|
||||
// LogUtils.e("fht", "getAllAppInfo onSuccess");
|
||||
// int code = body.getInteger("code");
|
||||
// String msg = body.getString("msg");
|
||||
// String data = body.getString("data");
|
||||
// List<AppInfo> applist = JSON.parseArray(data, AppInfo.class);
|
||||
// if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
// Message message = new Message();
|
||||
// message.what = 1;
|
||||
// message.obj = applist;
|
||||
// handler.sendMessage(message);
|
||||
// } else {
|
||||
// ToastUtil.show(msg);
|
||||
// handler.sendEmptyMessage(0);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e("Exception", e.getMessage());
|
||||
// ToastUtil.show("服务器错误,请稍后重试");
|
||||
// handler.sendEmptyMessage(0);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("getAllAppInfo", response.getException().toString());
|
||||
// ToastUtil.show("网络连接失败,检查网络连接");
|
||||
// handler.sendEmptyMessage(0);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// public static synchronized void checkDevicesInfo(final Context context) {
|
||||
// OkGo.<String>get(UrlAddress.GET_INFO_FROMESN)
|
||||
// .params("sn", Utils.getSerial())
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// Log.e("onSuccess", "checkDevicesInfo");
|
||||
// try {
|
||||
// JSONObject bodyObject = JSON.parseObject(response.body());
|
||||
// Integer code = (bodyObject.getInteger("code"));
|
||||
// String msg = bodyObject.getString("msg");
|
||||
// String data = bodyObject.getString("data");
|
||||
// SNInfo userInfo = JSON.parseObject(data, SNInfo.class);
|
||||
// if (code == 200) {
|
||||
// SPUtils.put(context, "isLogined", 1);
|
||||
// SPUtils.put(context, "member_id", userInfo.getMember_id());
|
||||
// SPUtils.put(context, "sn_id", userInfo.getId());
|
||||
// } else if (code == -200) {
|
||||
// SPUtils.put(context, "isLogined", 0);
|
||||
//
|
||||
// } else if (code == -250) {
|
||||
// SPUtils.put(context, "isLogined", 2);
|
||||
// //设备验证
|
||||
// }
|
||||
// } catch (Exception ex) {
|
||||
// Log.e("checkDevicesInfo", ex.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// Log.e("onError", response.getException().toString());
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// synchronized public static void getAllAppPackageName(final Handler handler) {
|
||||
// OkGo.<String>post(UrlAddress.GET_ALL_PACKAGENAME)
|
||||
// .params("sn", Utils.getSerial())
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// String s = response.body();
|
||||
// try {
|
||||
// JSONObject body = JSON.parseObject(s);
|
||||
// int code = body.getInteger("code");
|
||||
// String msg = body.getString("msg");
|
||||
// String data = body.getString("data");
|
||||
// if (code == 200) {
|
||||
// List<JSONObject> jsonArray = JSON.parseArray(data, JSONObject.class);
|
||||
// String packageList = "";
|
||||
// for (JSONObject jsonObject : jsonArray) {
|
||||
// packageList += jsonObject.getString("app_package") + ",";
|
||||
// }
|
||||
// if (!packageList.isEmpty()) {
|
||||
// Log.e("fht", packageList);
|
||||
// Message message = new Message();
|
||||
// message.what = 201;
|
||||
// message.obj = packageList;
|
||||
// handler.sendMessage(message);
|
||||
// } else {
|
||||
// handler.sendEmptyMessage(202);
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// synchronized public static void getRankApp(final Handler handler) {
|
||||
// OkGo.<String>get(UrlAddress.GET_ALL_RANK).execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// try {
|
||||
// JSONObject body = JSON.parseObject(response.body());
|
||||
//// LogUtils.e("onSuccess", body.toString());
|
||||
// LogUtils.e("fht", "getAllAppInfo onSuccess");
|
||||
// int code = body.getInteger("code");
|
||||
// String msg = body.getString("msg");
|
||||
// String data = body.getString("data");
|
||||
// List<AppInfo> applist = JSON.parseArray(data, AppInfo.class);
|
||||
// if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
// Message message = new Message();
|
||||
// message.what = 1;
|
||||
// message.obj = applist;
|
||||
// handler.sendMessage(message);
|
||||
// } else {
|
||||
// ToastUtil.show(msg);
|
||||
// handler.sendEmptyMessage(0);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e("Exception", e.getMessage());
|
||||
// ToastUtil.show("服务器错误,请稍后重试");
|
||||
// handler.sendEmptyMessage(0);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("getRankApp", response.getException().toString());
|
||||
// ToastUtil.show("网络连接失败,检查网络连接");
|
||||
// handler.sendEmptyMessage(0);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// synchronized public static void searchAppbyName(final Handler handler, String app_name) {
|
||||
// OkGo.<String>post(UrlAddress.GET_APPSEARCHE)
|
||||
// .params("sn", Utils.getSerial())
|
||||
// .params("app_name", app_name)
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// try {
|
||||
// JSONObject body = JSON.parseObject(response.body());
|
||||
// LogUtils.e("onSuccess", body.toString());
|
||||
LogUtils.e("fht", "getAllAppInfo onSuccess");
|
||||
int code = body.getInteger("code");
|
||||
String msg = body.getString("msg");
|
||||
String data = body.getString("data");
|
||||
List<AppInfo> applist = JSON.parseArray(data, AppInfo.class);
|
||||
if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
Message message = new Message();
|
||||
message.what = 1;
|
||||
message.obj = applist;
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
ToastUtil.show(msg);
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("Exception", e.getMessage());
|
||||
ToastUtil.show("服务器错误,请稍后重试");
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("getAllAppInfo", response.getException().toString());
|
||||
ToastUtil.show("网络连接失败,检查网络连接");
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
public static synchronized void checkDevicesInfo(final Context context) {
|
||||
OkGo.<String>post(Url.GET_INFO_FROMESN)
|
||||
.params("sn", Utils.getSerial())
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
Log.e("onSuccess", "checkDevicesInfo");
|
||||
try {
|
||||
JSONObject bodyObject = JSON.parseObject(response.body());
|
||||
Integer code = (bodyObject.getInteger("code"));
|
||||
String msg = bodyObject.getString("msg");
|
||||
String data = bodyObject.getString("data");
|
||||
UserInfo userInfo = JSON.parseObject(data, UserInfo.class);
|
||||
if (code == 200) {
|
||||
SPUtils.put(context, "isLogined", 1);
|
||||
SPUtils.put(context, "member_id", userInfo.getMember_id());
|
||||
SPUtils.put(context, "sn_id", userInfo.getId());
|
||||
} else if (code == -200) {
|
||||
SPUtils.put(context, "isLogined", 0);
|
||||
|
||||
} else if (code == -250) {
|
||||
SPUtils.put(context, "isLogined", 2);
|
||||
//设备验证
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Log.e("checkDevicesInfo", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
Log.e("onError", response.getException().toString());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
synchronized public static void getAllAppPackageName(final Handler handler) {
|
||||
OkGo.<String>post(Url.GET_ALL_PACKAGENAME)
|
||||
.params("sn", Utils.getSerial())
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
String s = response.body();
|
||||
try {
|
||||
JSONObject body = JSON.parseObject(s);
|
||||
int code = body.getInteger("code");
|
||||
String msg = body.getString("msg");
|
||||
String data = body.getString("data");
|
||||
if (code == 200) {
|
||||
List<JSONObject> jsonArray = JSON.parseArray(data, JSONObject.class);
|
||||
String packageList = "";
|
||||
for (JSONObject jsonObject : jsonArray) {
|
||||
packageList += jsonObject.getString("app_package") + ",";
|
||||
}
|
||||
if (!packageList.isEmpty()) {
|
||||
Log.e("fht", packageList);
|
||||
Message message = new Message();
|
||||
message.what = 201;
|
||||
message.obj = packageList;
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
handler.sendEmptyMessage(202);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
synchronized public static void getRankApp(final Handler handler) {
|
||||
OkGo.<String>get(Url.GET_ALL_RANK).execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
try {
|
||||
JSONObject body = JSON.parseObject(response.body());
|
||||
// LogUtils.e("onSuccess", body.toString());
|
||||
LogUtils.e("fht", "getAllAppInfo onSuccess");
|
||||
int code = body.getInteger("code");
|
||||
String msg = body.getString("msg");
|
||||
String data = body.getString("data");
|
||||
List<AppInfo> applist = JSON.parseArray(data, AppInfo.class);
|
||||
if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
Message message = new Message();
|
||||
message.what = 1;
|
||||
message.obj = applist;
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
ToastUtil.show(msg);
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("Exception", e.getMessage());
|
||||
ToastUtil.show("服务器错误,请稍后重试");
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("getRankApp", response.getException().toString());
|
||||
ToastUtil.show("网络连接失败,检查网络连接");
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
synchronized public static void searchAppbyName(final Handler handler, String app_name) {
|
||||
OkGo.<String>post(Url.GET_APPSEARCHE)
|
||||
.params("sn", Utils.getSerial())
|
||||
.params("app_name", app_name)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
try {
|
||||
JSONObject body = JSON.parseObject(response.body());
|
||||
LogUtils.e("onSuccess", body.toString());
|
||||
LogUtils.e("fht", "searchAppbyName onSuccess");
|
||||
int code = body.getInteger("code");
|
||||
String msg = body.getString("msg");
|
||||
String data = body.getString("data");
|
||||
List<AppInfo> applist = JSON.parseArray(data, AppInfo.class);
|
||||
if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
Message message = new Message();
|
||||
message.what = 1;
|
||||
message.obj = applist;
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
ToastUtil.show(msg);
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("Exception", e.getMessage());
|
||||
ToastUtil.show("服务器错误,请稍后重试");
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("searchAppbyName", response.getException().toString());
|
||||
ToastUtil.show("网络连接失败,检查网络连接");
|
||||
handler.sendEmptyMessage(0);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
synchronized public static void getUserInfo(final Handler handler) {
|
||||
String sn = Utils.getSerial();
|
||||
OkGo.<String>post(Url.GET_INFO_FROMESN)
|
||||
.params("sn", sn)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
LogUtils.e("fht", "getUserInfo onSuccess");
|
||||
JSONObject jsonObject = JSON.parseObject(response.body());
|
||||
int code = jsonObject.getInteger("code");
|
||||
String msg = jsonObject.getString("msg");
|
||||
if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
String data = jsonObject.getString("data");
|
||||
UserInfo userInfo = JSON.parseObject(data, UserInfo.class);
|
||||
Message message = new Message();
|
||||
message.what = 1;
|
||||
message.obj = userInfo;
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
ToastUtil.show(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("getUserInfo", response.getException().toString());
|
||||
ToastUtil.show("网络连接失败,检查网络连接");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
synchronized public static void getUserInfo(final Context context) {
|
||||
OkGo.<String>post(Url.GET_INFO_FROMESN)
|
||||
.params("sn", Utils.getSerial())
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
LogUtils.e("fht", "getUserInfo onSuccess");
|
||||
JSONObject jsonObject = JSON.parseObject(response.body());
|
||||
int code = jsonObject.getInteger("code");
|
||||
String msg = jsonObject.getString("msg");
|
||||
if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
String data = jsonObject.getString("data");
|
||||
UserInfo userInfo = JSON.parseObject(data, UserInfo.class);
|
||||
SPUtils.put(context, "member_id", userInfo.getMember_id());
|
||||
SPUtils.put(context, "sn_id", userInfo.getId());
|
||||
SPUtils.put(context, "sn_grade", userInfo.getSn_grade());
|
||||
} else {
|
||||
ToastUtil.show(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("getUserInfo", response.getException().toString());
|
||||
ToastUtil.show("网络连接失败,检查网络连接");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
synchronized public static void getSortApp(final Handler handler, int type, int grade, int subject) {
|
||||
OkGo.<String>post(Url.GET_SORT_APP)
|
||||
.params("sn", Utils.getSerial())
|
||||
.params("app_type", type)//应用分类 0学习 1娱乐
|
||||
.params("grade", grade)//年级 以数字代表
|
||||
.params("subject", subject) //科目 以数字代表
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
LogUtils.e("fht", "getSortApp onSuccess");
|
||||
JSONObject jsonObject = JSON.parseObject(response.body());
|
||||
LogUtils.e("fht", jsonObject.toString());
|
||||
int code = jsonObject.getInteger("code");
|
||||
String msg = jsonObject.getString("msg");
|
||||
if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
String data = jsonObject.getString("data");
|
||||
List<AppInfo> list = JSON.parseArray(data, AppInfo.class);
|
||||
Message message = new Message();
|
||||
message.what = 1;
|
||||
message.obj = list;
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
ToastUtil.show(msg);
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("getSortApp", response.getException().toString());
|
||||
ToastUtil.show("网络连接失败,检查网络连接");
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
synchronized public static void setAppinstallInfo(int member_id, String sn_id, String app_name, String packageName) {
|
||||
OkGo.<String>post(Url.SET_APP_INSTALL_INFO)
|
||||
.params("member_id", member_id)
|
||||
.params("sn_id", sn_id)
|
||||
.params("app_name", app_name)
|
||||
.params("package", packageName)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
JSONObject object = JSON.parseObject(response.body());
|
||||
int code = object.getInteger("code");
|
||||
String msg = object.getString("msg");
|
||||
LogUtils.e("setAppinstallInfo", msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("setAppinstallInfo", "onError:" + response.getException());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
synchronized public static void setAppuninstallInfo(String sn_id, String packageName) {
|
||||
OkGo.<String>post(Url.SET_APP_UNINSTALL_INFO)
|
||||
.params("sn_id", sn_id)
|
||||
.params("package", packageName)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
JSONObject object = JSON.parseObject(response.body());
|
||||
int code = object.getInteger("code");
|
||||
String msg = object.getString("msg");
|
||||
LogUtils.e("setAppinstallInfo", msg);
|
||||
if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("setAppinstallInfo", "onError:" + response.getException());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
synchronized public static void checkUpdateByPackage(final Handler handler, final String packageName, String versionCode) {
|
||||
OkGo.<String>post(Url.GET_APP_UPDATE)
|
||||
.params("code", versionCode)
|
||||
.params("package", packageName)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
try {
|
||||
JSONObject body = JSON.parseObject(response.body());
|
||||
int code = body.getInteger("code");
|
||||
String msg = body.getString("msg");
|
||||
if (code == 200) {
|
||||
Message message = new Message();
|
||||
JSONObject data = JSON.parseObject(body.getString("data"));
|
||||
if (data != null) {
|
||||
String url = data.getString("downloadurl");
|
||||
message.what = 200;
|
||||
message.obj = url;
|
||||
} else {
|
||||
message.what = -200;
|
||||
}
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
Log.e("checkUpdateByPackage", packageName + msg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("checkUpdateByPackage", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
Log.e("checkUpdateByPackage", response.getException().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void getBannerImg(final Handler handler) {
|
||||
OkGo.<String>get(Url.GET_BANNER_IMG).execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
try {
|
||||
JSONObject body = JSON.parseObject(response.body());
|
||||
int code = body.getInteger("code");
|
||||
String msg = body.getString("msg");
|
||||
if (code == 200) {
|
||||
Message message = new Message();
|
||||
List<bannerImage> data = JSON.parseArray(body.getString("data"), bannerImage.class);
|
||||
if (data != null) {
|
||||
List<String> urlList = new ArrayList<>();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
urlList.add(data.get(0).getImg());
|
||||
}
|
||||
message.what = 200;
|
||||
message.obj = urlList;
|
||||
} else {
|
||||
message.what = -200;
|
||||
}
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
Log.e("checkUpdateByPackage", msg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("checkUpdateByPackage", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static void getSubClassfy(final Handler handler) {
|
||||
OkGo.<String>post(Url.GET_SUBClASSFY)
|
||||
.params("sn", Utils.getSerial())
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(response.body());
|
||||
int code = jsonObject.getInteger("code");
|
||||
String msg = jsonObject.getString("msg");
|
||||
if (code == 200) {
|
||||
String data = jsonObject.getString("data");
|
||||
if (!data.equals("")) {
|
||||
List<String> list = Arrays.asList(data.split(","));
|
||||
Message message = new Message();
|
||||
message.what = 200;
|
||||
message.obj = list;
|
||||
handler.sendMessage(message);
|
||||
}
|
||||
} else {
|
||||
ToastUtil.debugShow(msg);
|
||||
handler.sendEmptyMessage(-200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
// LogUtils.e("fht", "searchAppbyName onSuccess");
|
||||
// int code = body.getInteger("code");
|
||||
// String msg = body.getString("msg");
|
||||
// String data = body.getString("data");
|
||||
// List<AppInfo> applist = JSON.parseArray(data, AppInfo.class);
|
||||
// if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
// Message message = new Message();
|
||||
// message.what = 1;
|
||||
// message.obj = applist;
|
||||
// handler.sendMessage(message);
|
||||
// } else {
|
||||
// ToastUtil.show(msg);
|
||||
// handler.sendEmptyMessage(0);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e("Exception", e.getMessage());
|
||||
// ToastUtil.show("服务器错误,请稍后重试");
|
||||
// handler.sendEmptyMessage(0);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("searchAppbyName", response.getException().toString());
|
||||
// ToastUtil.show("网络连接失败,检查网络连接");
|
||||
// handler.sendEmptyMessage(0);
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// synchronized public static void getUserInfo(final Handler handler) {
|
||||
// String sn = Utils.getSerial();
|
||||
// OkGo.<String>get(UrlAddress.GET_INFO_FROMESN)
|
||||
// .params("sn", sn)
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// LogUtils.e("fht", "getUserInfo onSuccess");
|
||||
// JSONObject jsonObject = JSON.parseObject(response.body());
|
||||
// int code = jsonObject.getInteger("code");
|
||||
// String msg = jsonObject.getString("msg");
|
||||
// if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
// String data = jsonObject.getString("data");
|
||||
// SNInfo userInfo = JSON.parseObject(data, SNInfo.class);
|
||||
// Message message = new Message();
|
||||
// message.what = 1;
|
||||
// message.obj = userInfo;
|
||||
// handler.sendMessage(message);
|
||||
// } else {
|
||||
// ToastUtil.show(msg);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("getUserInfo", response.getException().toString());
|
||||
// ToastUtil.show("网络连接失败,检查网络连接");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// synchronized public static void getUserInfo(final Context context) {
|
||||
// OkGo.<String>get(UrlAddress.GET_INFO_FROMESN)
|
||||
// .params("sn", Utils.getSerial())
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// LogUtils.e("fht", "getUserInfo onSuccess");
|
||||
// JSONObject jsonObject = JSON.parseObject(response.body());
|
||||
// int code = jsonObject.getInteger("code");
|
||||
// String msg = jsonObject.getString("msg");
|
||||
// if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
// String data = jsonObject.getString("data");
|
||||
// SNInfo userInfo = JSON.parseObject(data, SNInfo.class);
|
||||
// SPUtils.put(context, "member_id", userInfo.getMember_id());
|
||||
// SPUtils.put(context, "sn_id", userInfo.getId());
|
||||
// SPUtils.put(context, "sn_grade", userInfo.getSn_grade());
|
||||
// } else {
|
||||
// ToastUtil.show(msg);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("getUserInfo", response.getException().toString());
|
||||
// ToastUtil.show("网络连接失败,检查网络连接");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// synchronized public static void getSortApp(final Handler handler, int type, int grade, int subject) {
|
||||
// OkGo.<String>post(UrlAddress.GET_SORT_APP)
|
||||
// .params("sn", Utils.getSerial())
|
||||
// .params("app_type", type)//应用分类 0学习 1娱乐
|
||||
// .params("grade", grade)//年级 以数字代表
|
||||
// .params("subject", subject) //科目 以数字代表
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// LogUtils.e("fht", "getSortApp onSuccess");
|
||||
// JSONObject jsonObject = JSON.parseObject(response.body());
|
||||
// LogUtils.e("fht", jsonObject.toString());
|
||||
// int code = jsonObject.getInteger("code");
|
||||
// String msg = jsonObject.getString("msg");
|
||||
// if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
// String data = jsonObject.getString("data");
|
||||
// List<AppInfo> list = JSON.parseArray(data, AppInfo.class);
|
||||
// Message message = new Message();
|
||||
// message.what = 1;
|
||||
// message.obj = list;
|
||||
// handler.sendMessage(message);
|
||||
// } else {
|
||||
// ToastUtil.show(msg);
|
||||
// handler.sendEmptyMessage(0);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("getSortApp", response.getException().toString());
|
||||
// ToastUtil.show("网络连接失败,检查网络连接");
|
||||
// handler.sendEmptyMessage(0);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// synchronized public static void setAppinstallInfo(int member_id, String sn_id, String app_name, String packageName) {
|
||||
// OkGo.<String>post(UrlAddress.SET_APP_INSTALL_INFO)
|
||||
// .params("member_id", member_id)
|
||||
// .params("sn_id", sn_id)
|
||||
// .params("app_name", app_name)
|
||||
// .params("package", packageName)
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// JSONObject object = JSON.parseObject(response.body());
|
||||
// int code = object.getInteger("code");
|
||||
// String msg = object.getString("msg");
|
||||
// LogUtils.e("setAppinstallInfo", msg);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("setAppinstallInfo", "onError:" + response.getException());
|
||||
//
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
//
|
||||
// synchronized public static void setAppuninstallInfo(String sn_id, String packageName) {
|
||||
// OkGo.<String>post(UrlAddress.SET_APP_UNINSTALL_INFO)
|
||||
// .params("sn_id", sn_id)
|
||||
// .params("package", packageName)
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// JSONObject object = JSON.parseObject(response.body());
|
||||
// int code = object.getInteger("code");
|
||||
// String msg = object.getString("msg");
|
||||
// LogUtils.e("setAppinstallInfo", msg);
|
||||
// if (code == MessageWhat.CODE_SUCCESSFUL) {
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("setAppinstallInfo", "onError:" + response.getException());
|
||||
//
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
//
|
||||
// synchronized public static void checkUpdateByPackage(final Handler handler, final String packageName, String versionCode) {
|
||||
// OkGo.<String>post(UrlAddress.GET_APP_UPDATE)
|
||||
// .params("code", versionCode)
|
||||
// .params("package", packageName)
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// try {
|
||||
// JSONObject body = JSON.parseObject(response.body());
|
||||
// int code = body.getInteger("code");
|
||||
// String msg = body.getString("msg");
|
||||
// if (code == 200) {
|
||||
// Message message = new Message();
|
||||
// JSONObject data = JSON.parseObject(body.getString("data"));
|
||||
// if (data != null) {
|
||||
// String url = data.getString("downloadurl");
|
||||
// message.what = 200;
|
||||
// message.obj = url;
|
||||
// } else {
|
||||
// message.what = -200;
|
||||
// }
|
||||
// handler.sendMessage(message);
|
||||
// } else {
|
||||
// Log.e("checkUpdateByPackage", packageName + msg);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// Log.e("checkUpdateByPackage", e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// Log.e("checkUpdateByPackage", response.getException().toString());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// public static void getBannerImg(final Handler handler) {
|
||||
// OkGo.<String>get(UrlAddress.GET_BANNER_IMG).execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// try {
|
||||
// JSONObject body = JSON.parseObject(response.body());
|
||||
// int code = body.getInteger("code");
|
||||
// String msg = body.getString("msg");
|
||||
// if (code == 200) {
|
||||
// Message message = new Message();
|
||||
// List<bannerImage> data = JSON.parseArray(body.getString("data"), bannerImage.class);
|
||||
// if (data != null) {
|
||||
// List<String> urlList = new ArrayList<>();
|
||||
// for (int i = 0; i < data.size(); i++) {
|
||||
// urlList.add(data.get(0).getImg());
|
||||
// }
|
||||
// message.what = 200;
|
||||
// message.obj = urlList;
|
||||
// } else {
|
||||
// message.what = -200;
|
||||
// }
|
||||
// handler.sendMessage(message);
|
||||
// } else {
|
||||
// Log.e("checkUpdateByPackage", msg);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// Log.e("checkUpdateByPackage", e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public static void getSubClassfy(final Handler handler) {
|
||||
// OkGo.<String>post(UrlAddress.GET_SUBClASSFY)
|
||||
// .params("sn", Utils.getSerial())
|
||||
// .execute(new StringCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(Response<String> response) {
|
||||
// JSONObject jsonObject = JSONObject.parseObject(response.body());
|
||||
// int code = jsonObject.getInteger("code");
|
||||
// String msg = jsonObject.getString("msg");
|
||||
// if (code == 200) {
|
||||
// String data = jsonObject.getString("data");
|
||||
// if (!data.equals("")) {
|
||||
// List<String> list = Arrays.asList(data.split(","));
|
||||
// Message message = new Message();
|
||||
// message.what = 200;
|
||||
// message.obj = list;
|
||||
// handler.sendMessage(message);
|
||||
// }
|
||||
// } else {
|
||||
// ToastUtil.debugShow(msg);
|
||||
// handler.sendEmptyMessage(-200);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<String> response) {
|
||||
// super.onError(response);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.appstore.uiui.network.URLs;
|
||||
|
||||
public class Url {
|
||||
public final static String NETWORK_HOME_ADDRESS = "http://homework.tuiinfo.com/api/";
|
||||
|
||||
public final static String GET_ALL_APPINFO = NETWORK_HOME_ADDRESS + "App/allInfo";
|
||||
//获取所有应用
|
||||
public final static String GET_ALL_RANK = NETWORK_HOME_ADDRESS + "App/rankings";
|
||||
//获取所有应用排行
|
||||
public final static String GET_APPSEARCHE = NETWORK_HOME_ADDRESS + "App/appSearch";
|
||||
//搜索应用
|
||||
public final static String GET_INFO_FROMESN = NETWORK_HOME_ADDRESS + "Member/snInfo";
|
||||
//通过SN获取绑定信息
|
||||
public final static String GET_SORT_APP = NETWORK_HOME_ADDRESS + "App/sortApp";
|
||||
//app分类查询
|
||||
public final static String SET_APP_INSTALL_INFO = NETWORK_HOME_ADDRESS + "App/appInstall";
|
||||
//发送app安装信息
|
||||
public final static String SET_APP_UNINSTALL_INFO = NETWORK_HOME_ADDRESS + "App/appUnload";
|
||||
//发送app卸载信息
|
||||
public final static String GET_APP_UPDATE = NETWORK_HOME_ADDRESS + "Update/update";
|
||||
//根据包名获取更新
|
||||
public final static String GET_BANNER_IMG = NETWORK_HOME_ADDRESS + "Slideshow/getImg";
|
||||
//获取banner图
|
||||
public final static String GET_ALL_PACKAGENAME = NETWORK_HOME_ADDRESS + "App/allPackageSn";
|
||||
//获取所有应用包名
|
||||
public final static String GET_SUBClASSFY = NETWORK_HOME_ADDRESS + "Application/getSubClassfy";
|
||||
//获取应用分类
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.appstore.uiui.network.URLs;
|
||||
|
||||
public class UrlAddress {
|
||||
public final static String ROOT_URL = "http://homework.uiuios.com/android/";
|
||||
|
||||
public final static String GET_ALL_APPINFO = ROOT_URL + "app/queryAllApp";
|
||||
//获取所有应用
|
||||
public final static String GET_ALL_RANK = ROOT_URL + "App/rankings";
|
||||
//获取所有应用排行
|
||||
public final static String GET_APPSEARCHE = ROOT_URL + "App/appSearch";
|
||||
//搜索应用
|
||||
public final static String GET_INFO_FROMESN = ROOT_URL + "sn/getSnInfo";
|
||||
//通过SN获取绑定信息
|
||||
public final static String GET_SORT_APP = ROOT_URL + "App/sortApp";
|
||||
//app分类查询
|
||||
public final static String SET_APP_INSTALL_INFO = ROOT_URL + "App/appInstall";
|
||||
//发送app安装信息
|
||||
public final static String SET_APP_UNINSTALL_INFO = ROOT_URL + "App/appUnload";
|
||||
//发送app卸载信息
|
||||
public final static String GET_APP_UPDATE = ROOT_URL + "Update/update";
|
||||
//根据包名获取更新
|
||||
public final static String GET_BANNER_IMG = ROOT_URL + "app/getBrand";
|
||||
//获取banner图
|
||||
public final static String GET_ALL_PACKAGENAME = ROOT_URL + "App/allPackageSn";
|
||||
//获取所有应用包名
|
||||
public final static String GET_SUBClASSFY = ROOT_URL + "Application/getSubClassfy";
|
||||
//获取应用分类
|
||||
public final static String SEND_DOWNLOADAPP = ROOT_URL + "app/downloadApp";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.appstore.uiui.network.api;
|
||||
|
||||
import com.appstore.uiui.bean.BaseResponse;
|
||||
import com.appstore.uiui.bean.ImageUrl;
|
||||
import com.appstore.uiui.network.URLs.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface BannerImage {
|
||||
@GET(UrlAddress.GET_BANNER_IMG)
|
||||
Observable<BaseResponse<List<ImageUrl>>> getImageURL(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.appstore.uiui.network.api;
|
||||
|
||||
import com.appstore.uiui.bean.BaseResponse;
|
||||
import com.appstore.uiui.network.URLs.UrlAddress;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface DownloadApp {
|
||||
@FormUrlEncoded
|
||||
@POST(UrlAddress.SEND_DOWNLOADAPP)
|
||||
Observable<BaseResponse>sendDownloadApp(
|
||||
@Field("package_name")String package_name,
|
||||
@Field("app_size")long app_size,
|
||||
@Field("sn")String sn,
|
||||
@Field("userId")int userId
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.appstore.uiui.network.api;
|
||||
|
||||
import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.bean.BaseResponse;
|
||||
import com.appstore.uiui.bean.UserInfo;
|
||||
import com.appstore.uiui.network.URLs.UrlAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface QueryAllApp {
|
||||
@GET(UrlAddress.GET_ALL_APPINFO)
|
||||
Observable<BaseResponse<List<AppInfo>>> getAllApp(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
}
|
||||
16
app/src/main/java/com/appstore/uiui/network/api/SNInfo.java
Normal file
16
app/src/main/java/com/appstore/uiui/network/api/SNInfo.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.appstore.uiui.network.api;
|
||||
|
||||
import com.appstore.uiui.bean.BaseResponse;
|
||||
import com.appstore.uiui.bean.UserInfo;
|
||||
import com.appstore.uiui.network.URLs.UrlAddress;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface SNInfo {
|
||||
@GET(UrlAddress.GET_INFO_FROMESN)
|
||||
Observable<BaseResponse<UserInfo>> getUserinfo(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
}
|
||||
@@ -20,8 +20,8 @@ public class AppManagerReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int member_id = (int) SPUtils.get(context, "member_id", -1);
|
||||
String sn_id = (String) SPUtils.get(context, "sn_id", "-1");
|
||||
int admin_id = (int) SPUtils.get(context, "admin_id", -1);
|
||||
int sn_id = (int) SPUtils.get(context, "sn_id", -1);
|
||||
Log.e("BootReceiver", intent.getAction());
|
||||
|
||||
action = intent.getAction();
|
||||
@@ -42,10 +42,10 @@ public class AppManagerReceiver extends BroadcastReceiver {
|
||||
LogUtils.e(TAG, "安装了:" + packageName + "包名的程序");
|
||||
// ToastTool.show("安装成功");
|
||||
if (!packageName.equals(context.getPackageName()) && !Arrays.asList(packages).contains(packageName)) {
|
||||
if (member_id == -1 || sn_id.equals("-1")) {
|
||||
OKGO.getUserInfo(context);
|
||||
if (admin_id == -1 || sn_id == -1) {
|
||||
// OKGO.getUserInfo(context);
|
||||
} else {
|
||||
OKGO.setAppinstallInfo(member_id, sn_id, name, packageName);
|
||||
// OKGO.setAppinstallInfo(member_id, sn_id, name, packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,11 +56,11 @@ public class AppManagerReceiver extends BroadcastReceiver {
|
||||
LogUtils.e(TAG, "卸载了:" + packageName + "包名的程序");
|
||||
Intent intents = new Intent("com.appstore.uiui.PACKAGE_REMOVED");
|
||||
context.sendBroadcast(intents);
|
||||
if (!packageName.equals(context.getPackageName())&& !Arrays.asList(packages).contains(packageName)) {
|
||||
if (member_id == -1 || sn_id.equals("-1")) {
|
||||
OKGO.getUserInfo(context);
|
||||
if (!packageName.equals(context.getPackageName()) && !Arrays.asList(packages).contains(packageName)) {
|
||||
if (admin_id == -1 || sn_id == -1) {
|
||||
// OKGO.getUserInfo(context);
|
||||
} else {
|
||||
OKGO.setAppuninstallInfo(sn_id, packageName);
|
||||
// OKGO.setAppuninstallInfo(sn_id, packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,7 @@ public class AppManagerReceiver extends BroadcastReceiver {
|
||||
|
||||
|
||||
}
|
||||
|
||||
String[] packages = {
|
||||
"com.appstore.uiui",
|
||||
"com.uiuios.updatetools",
|
||||
|
||||
@@ -17,7 +17,7 @@ public class BootReceiver extends BroadcastReceiver {
|
||||
context.startService(new Intent(context, InitJpushServer.class));
|
||||
context.startService(new Intent(context, StepService.class));
|
||||
context.startService(new Intent(context, GuardService.class));
|
||||
OKGO.getUserInfo(context);
|
||||
// OKGO.getUserInfo(context);
|
||||
LogUtils.e("fht", "booting BootReceiver");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,22 +23,28 @@ import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.appstore.uiui.KeepAliveConnection;
|
||||
import com.appstore.uiui.network.OKGO;
|
||||
import com.appstore.uiui.bean.BaseResponse;
|
||||
import com.appstore.uiui.network.NetWorkManager;
|
||||
import com.appstore.uiui.network.api.DownloadApp;
|
||||
import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.LogUtils;
|
||||
import com.appstore.uiui.utils.SPUtils;
|
||||
import com.appstore.uiui.utils.ServiceAliveUtils;
|
||||
import com.appstore.uiui.utils.Utils;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.FileCallback;
|
||||
import com.lzy.okgo.model.Progress;
|
||||
import com.lzy.okgo.model.Response;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
/**
|
||||
* 守护进程 双进程通讯
|
||||
@@ -83,7 +89,7 @@ public class GuardService extends Service {
|
||||
Aria.init(this);
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||
Aria.download(this).register();
|
||||
OKGO.getAllAppPackageName(handler);
|
||||
// OKGO.getAllAppPackageName(handler);
|
||||
CheckUpdateBySNinfo();
|
||||
// startForeground(1, new Notification());
|
||||
// 绑定建立链接
|
||||
@@ -101,9 +107,9 @@ public class GuardService extends Service {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (null != packageInfo) {
|
||||
OKGO.checkUpdateByPackage(handler, packageInfo.packageName, String.valueOf(packageInfo.versionCode));
|
||||
// OKGO.checkUpdateByPackage(handler, packageInfo.packageName, String.valueOf(packageInfo.versionCode));
|
||||
} else {
|
||||
OKGO.checkUpdateByPackage(handler, "com.info.sn", "0");
|
||||
// OKGO.checkUpdateByPackage(handler, "com.info.sn", "0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,12 +120,12 @@ public class GuardService extends Service {
|
||||
switch (msg.what) {
|
||||
case 200:
|
||||
String url = (String) msg.obj;
|
||||
getFile(url);
|
||||
// getFile(url);
|
||||
break;
|
||||
case 201:
|
||||
String apppackage = (String) msg.obj;
|
||||
Log.e("fht", Settings.System.getString(getContentResolver(), "qch_app_forbid") + "?");
|
||||
if (Settings.System.putString(getContentResolver(), "qch_app_forbid", apppackage+ "com.info.sn,com.android.uiuios,com.appstore.uiui,com.uiuios.updatetools")) {
|
||||
if (Settings.System.putString(getContentResolver(), "qch_app_forbid", apppackage + "com.info.sn,com.android.uiuios,com.appstore.uiui,com.uiuios.updatetools")) {
|
||||
Log.e("fht", "app package write successful");
|
||||
}
|
||||
break;
|
||||
@@ -129,52 +135,80 @@ public class GuardService extends Service {
|
||||
}
|
||||
};
|
||||
|
||||
private void getFile(String url) {
|
||||
OkGo.<File>get(url)
|
||||
.execute(new FileCallback() {
|
||||
@Override
|
||||
public void onSuccess(final Response<File> response) {
|
||||
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApkUtils.installApp(GuardService.this, response.body().getAbsolutePath());
|
||||
}
|
||||
}).start();
|
||||
LogUtils.e("getFile", "download file successful,now installing");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<File> response) {
|
||||
super.onError(response);
|
||||
LogUtils.e("getFile", "File download Failure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadProgress(Progress progress) {
|
||||
super.downloadProgress(progress);
|
||||
LogUtils.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
|
||||
}
|
||||
});
|
||||
}
|
||||
// private void getFile(String url) {
|
||||
// OkGo.<File>get(url)
|
||||
// .execute(new FileCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(final Response<File> response) {
|
||||
//// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
||||
// new Thread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// ApkUtils.installApp(GuardService.this, response.body().getAbsolutePath());
|
||||
// }
|
||||
// }).start();
|
||||
// LogUtils.e("getFile", "download file successful,now installing");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Response<File> response) {
|
||||
// super.onError(response);
|
||||
// LogUtils.e("getFile", "File download Failure");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void downloadProgress(Progress progress) {
|
||||
// super.downloadProgress(progress);
|
||||
// LogUtils.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@Download.onTaskRunning
|
||||
protected void running(DownloadTask task) {
|
||||
LogUtils.e("mjsheng", "我在下载=--------------::" + task.getState() + "-------" + task.getPercent() + "-------" + task.getExtendField());
|
||||
ToastUtils.showShort("我在下载=--------------::" + task.getExtendField() + "-------" + task.getPercent());
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(DownloadTask task) {
|
||||
//在这里处理任务完成的状态
|
||||
final String downloadPath = task.getFilePath();
|
||||
String packageName = task.getExtendField();
|
||||
LogUtils.e("mjsheng", "downloadPath::" + downloadPath);
|
||||
LogUtils.e("mjsheng", "extendField::" + packageName);
|
||||
if (packageName.equalsIgnoreCase(this.getPackageName())) {
|
||||
ApkUtils.installApp(this,downloadPath);
|
||||
} else {
|
||||
if (null != task.getExtendField()) {
|
||||
JSONObject jsonObject = JSON.parseObject(task.getExtendField());
|
||||
String packageName = jsonObject.getString("app_package");
|
||||
File file = new File(downloadPath);
|
||||
int admin_id = (int) SPUtils.get(GuardService.this, "admin_id", -1);
|
||||
DownloadApp downloadApp = NetWorkManager.getDownloadAppControl();
|
||||
downloadApp.sendDownloadApp(packageName, file.length(), Utils.getSerial(), admin_id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@io.reactivex.annotations.NonNull BaseResponse baseResponse) {
|
||||
int code = baseResponse.code;
|
||||
String msg = baseResponse.msg;
|
||||
Log.e("taskComplete", "onNext: " + "code" + code + ",msg:" + msg);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.annotations.NonNull Throwable e) {
|
||||
Log.e("taskComplete", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -182,6 +216,5 @@ public class GuardService extends Service {
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,15 +36,8 @@ import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Observer;
|
||||
import rx.Subscriber;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public class ApkUtils {
|
||||
|
||||
|
||||
public static synchronized boolean getRootAhth() {
|
||||
Process process = null;
|
||||
DataOutputStream os = null;
|
||||
@@ -115,6 +108,17 @@ public class ApkUtils {
|
||||
}
|
||||
context.startActivity(intent);
|
||||
}
|
||||
/**
|
||||
* 卸载一个app
|
||||
*/
|
||||
public static void Uninstall(Context context, String packageName) {
|
||||
//通过程序的包名创建URI
|
||||
Uri packageURI = Uri.parse("package:" + packageName);
|
||||
//创建Intent意图
|
||||
Intent intent = new Intent(Intent.ACTION_DELETE, packageURI);
|
||||
//执行卸载程序
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据包名卸载应用
|
||||
@@ -213,94 +217,94 @@ public class ApkUtils {
|
||||
}
|
||||
|
||||
|
||||
public static void installRx(final Context context, final String packageName, final String filePath) {
|
||||
|
||||
Observable.create(new Observable.OnSubscribe<Integer>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super Integer> subscriber) {
|
||||
File file = new File(filePath);
|
||||
if (filePath == null || filePath.length() == 0 || file == null) {
|
||||
Log.e("fanhuitong", "errormesg=========" + " 空啊 ");
|
||||
subscriber.onNext(0);
|
||||
return;
|
||||
}
|
||||
// String[] args = { "pm", "install", "-r", filePath };
|
||||
String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath};
|
||||
// String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath;
|
||||
Log.e("fanhuitong", "argss====" + args);
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(args);
|
||||
Process process = null;
|
||||
BufferedReader successResult = null;
|
||||
BufferedReader errorResult = null;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder errorMsg = new StringBuilder();
|
||||
try {
|
||||
process = processBuilder.start();
|
||||
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
String s;
|
||||
while ((s = successResult.readLine()) != null) {
|
||||
Log.e("mjhseng", "successResult----------" + s);
|
||||
successMsg.append(s);
|
||||
}
|
||||
while ((s = errorResult.readLine()) != null) {
|
||||
Log.e("mjhseng", "errorResult----------" + s);
|
||||
errorMsg.append(s);
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
Log.e("fanhuitong", "IOException e1)----------" + e1.toString());
|
||||
e1.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (successResult != null) {
|
||||
successResult.close();
|
||||
}
|
||||
if (errorResult != null) {
|
||||
errorResult.close();
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
Log.e("fanhuitong", "IOException e11)---------" + e1.toString());
|
||||
e1.printStackTrace();
|
||||
}
|
||||
if (process != null) {
|
||||
process.destroy();
|
||||
}
|
||||
}
|
||||
if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) {
|
||||
subscriber.onNext(2);
|
||||
} else {
|
||||
Log.e("fanhuitong", "errormesg=========" + errorMsg.toString());
|
||||
subscriber.onNext(1);
|
||||
}
|
||||
}
|
||||
}).subscribeOn(Schedulers.newThread())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<Integer>() {
|
||||
|
||||
@Override
|
||||
public void onNext(Integer value) {
|
||||
if (value == 2) {
|
||||
//安装成功
|
||||
Utils.showToast(context, "安装成功");
|
||||
Log.e("fanhuitong", "-----------安装成功-----------");
|
||||
} else {
|
||||
//安装错误
|
||||
Log.e("fanhuitong", "------------安装错误-----------");
|
||||
Utils.showToast(context, "安装失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
//安装错误
|
||||
}
|
||||
});
|
||||
}
|
||||
// public static void installRx(final Context context, final String packageName, final String filePath) {
|
||||
//
|
||||
// Observable.create(new Observable.OnSubscribe<Integer>() {
|
||||
// @Override
|
||||
// public void call(Subscriber<? super Integer> subscriber) {
|
||||
// File file = new File(filePath);
|
||||
// if (filePath == null || filePath.length() == 0 || file == null) {
|
||||
// Log.e("fanhuitong", "errormesg=========" + " 空啊 ");
|
||||
// subscriber.onNext(0);
|
||||
// return;
|
||||
// }
|
||||
// // String[] args = { "pm", "install", "-r", filePath };
|
||||
// String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath};
|
||||
// // String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath;
|
||||
// Log.e("fanhuitong", "argss====" + args);
|
||||
// ProcessBuilder processBuilder = new ProcessBuilder(args);
|
||||
// Process process = null;
|
||||
// BufferedReader successResult = null;
|
||||
// BufferedReader errorResult = null;
|
||||
// StringBuilder successMsg = new StringBuilder();
|
||||
// StringBuilder errorMsg = new StringBuilder();
|
||||
// try {
|
||||
// process = processBuilder.start();
|
||||
// successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
// errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
// String s;
|
||||
// while ((s = successResult.readLine()) != null) {
|
||||
// Log.e("mjhseng", "successResult----------" + s);
|
||||
// successMsg.append(s);
|
||||
// }
|
||||
// while ((s = errorResult.readLine()) != null) {
|
||||
// Log.e("mjhseng", "errorResult----------" + s);
|
||||
// errorMsg.append(s);
|
||||
// }
|
||||
// } catch (IOException e1) {
|
||||
// Log.e("fanhuitong", "IOException e1)----------" + e1.toString());
|
||||
// e1.printStackTrace();
|
||||
// } finally {
|
||||
// try {
|
||||
// if (successResult != null) {
|
||||
// successResult.close();
|
||||
// }
|
||||
// if (errorResult != null) {
|
||||
// errorResult.close();
|
||||
// }
|
||||
// } catch (IOException e1) {
|
||||
// Log.e("fanhuitong", "IOException e11)---------" + e1.toString());
|
||||
// e1.printStackTrace();
|
||||
// }
|
||||
// if (process != null) {
|
||||
// process.destroy();
|
||||
// }
|
||||
// }
|
||||
// if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) {
|
||||
// subscriber.onNext(2);
|
||||
// } else {
|
||||
// Log.e("fanhuitong", "errormesg=========" + errorMsg.toString());
|
||||
// subscriber.onNext(1);
|
||||
// }
|
||||
// }
|
||||
// }).subscribeOn(Schedulers.newThread())
|
||||
// .observeOn(AndroidSchedulers.mainThread())
|
||||
// .subscribe(new Observer<Integer>() {
|
||||
//
|
||||
// @Override
|
||||
// public void onNext(Integer value) {
|
||||
// if (value == 2) {
|
||||
// //安装成功
|
||||
// Utils.showToast(context, "安装成功");
|
||||
// Log.e("fanhuitong", "-----------安装成功-----------");
|
||||
// } else {
|
||||
// //安装错误
|
||||
// Log.e("fanhuitong", "------------安装错误-----------");
|
||||
// Utils.showToast(context, "安装失败");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onCompleted() {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Throwable e) {
|
||||
// //安装错误
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
public static void installApp(Context context, String filePath) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
@@ -595,5 +599,37 @@ public class ApkUtils {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static boolean isInstalled(Context context, String packageName) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
PackageInfo info = null;
|
||||
try {
|
||||
info = pm.getPackageInfo(packageName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return info != null;
|
||||
}
|
||||
|
||||
public static boolean isUpdate(Context context, String packageName, int versionCode) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
PackageInfo info = null;
|
||||
try {
|
||||
info = pm.getPackageInfo(packageName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (info != null) {
|
||||
long appVersionCode;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
appVersionCode = info.getLongVersionCode();
|
||||
} else {
|
||||
appVersionCode = info.versionCode;
|
||||
}
|
||||
return versionCode > appVersionCode;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
123
app/src/main/java/com/appstore/uiui/utils/FileUtils.java
Normal file
123
app/src/main/java/com/appstore/uiui/utils/FileUtils.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package com.appstore.uiui.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.appstore.uiui.base.FilePath;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class FileUtils {
|
||||
public static String getFileNamefromURL(String url) {
|
||||
int position = url.lastIndexOf("/");
|
||||
return url.substring(position + 1);
|
||||
}
|
||||
|
||||
public static String getMD5fromFileName(String fileName) {
|
||||
int position = fileName.lastIndexOf("/");
|
||||
return fileName.substring(position + 9, fileName.length() - 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个文件的MD5值
|
||||
*
|
||||
* @param file 文件
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static String getFileMD5s(File file) {
|
||||
if (!file.isFile()) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest digest = null;
|
||||
FileInputStream in = null;
|
||||
byte buffer[] = new byte[1024];
|
||||
int len;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
in = new FileInputStream(file);
|
||||
while ((len = in.read(buffer, 0, 1024)) != -1) {
|
||||
digest.update(buffer, 0, len);
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
BigInteger bigInt = new BigInteger(1, digest.digest());
|
||||
return bigInt.toString(32);
|
||||
}
|
||||
|
||||
public static void ariaDownload(Context context, String url, JSONObject jsonObject) {
|
||||
String fileName = getFileNamefromURL(url);
|
||||
String urlMD5 = jsonObject.getString("MD5");
|
||||
Log.e("ariaDownload", "urlMD5=" + urlMD5);
|
||||
File file = new File(FilePath.FileDownloadPath + "/jgy/" + fileName);
|
||||
if (file.exists() && !file.isDirectory()) {
|
||||
String filenameMD5 = getMD5fromFileName(url);
|
||||
|
||||
String fileMD5 = FileUtils.getFileMD5s(file);
|
||||
Log.e("ariaDownload", "filenameMD5=" + filenameMD5);
|
||||
Log.e("ariaDownload", "fileMD5=" + fileMD5);
|
||||
//后端还没有完成json字段的MD5,暂时用文件名获取
|
||||
if (fileMD5.equalsIgnoreCase(filenameMD5)) {
|
||||
ApkUtils.installApp(context, file.getAbsolutePath());
|
||||
} else {
|
||||
Aria.download(context)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(FilePath.FileDownloadPath + "/jgy/" + fileName, true)
|
||||
.setExtendField(jsonObject.toJSONString())
|
||||
.create(); //启动下载}
|
||||
// SaveListUtils.addDownLoadList(app_package);
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
Aria.download(context)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(FilePath.FileDownloadPath + "/jgy/" + fileName, true)
|
||||
.setExtendField(jsonObject.toJSONString())
|
||||
.create(); //启动下载}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化文件大小
|
||||
*
|
||||
* @param size file.length() 获取文件大小
|
||||
*/
|
||||
public static String formatFileSize(double size) {
|
||||
if (size < 0) {
|
||||
return "0kb";
|
||||
}
|
||||
double kiloByte = size / 1024;
|
||||
if (kiloByte < 1) {
|
||||
return size + "b";
|
||||
}
|
||||
|
||||
double megaByte = kiloByte / 1024;
|
||||
if (megaByte < 1) {
|
||||
BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
|
||||
return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "kb";
|
||||
}
|
||||
|
||||
double gigaByte = megaByte / 1024;
|
||||
if (gigaByte < 1) {
|
||||
BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
|
||||
return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "mb";
|
||||
}
|
||||
|
||||
double teraBytes = gigaByte / 1024;
|
||||
if (teraBytes < 1) {
|
||||
BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
|
||||
return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "gb";
|
||||
}
|
||||
BigDecimal result4 = new BigDecimal(teraBytes);
|
||||
return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "tb";
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.appstore.uiui.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.appstore.uiui.common.CommonDatas;
|
||||
import com.blankj.utilcode.util.SPStaticUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SaveListUtils {
|
||||
private static List<String> downLoadList = new ArrayList<>();
|
||||
|
||||
public static List<String> getList() {
|
||||
String data = SPStaticUtils.getString(CommonDatas.FORCE_INSTALL);
|
||||
Log.e("mjshenglistdata", data);
|
||||
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<List<String>>() {
|
||||
}.getType();
|
||||
List<String> list = gson.fromJson(data, listType);
|
||||
|
||||
// Log.e("mjshenglist1", list.toString());
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void addToList(String data) {
|
||||
List<String> list = getList();
|
||||
// Log.e("mjshenglist2", list.toString());
|
||||
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
if (!list.contains(data)) {
|
||||
list.add(data);
|
||||
Gson gson = new Gson();
|
||||
String gsonData = gson.toJson(list);
|
||||
SPStaticUtils.put(CommonDatas.FORCE_INSTALL, gsonData);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getDownLoadList() {
|
||||
|
||||
return downLoadList;
|
||||
}
|
||||
|
||||
public static void addDownLoadList(String packageName) {
|
||||
if (downLoadList == null) {
|
||||
downLoadList = new ArrayList<>();
|
||||
downLoadList.add(packageName);
|
||||
} else {
|
||||
if (!downLoadList.contains(packageName)) {
|
||||
downLoadList.add(packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDownLoading(String packageName) {
|
||||
if (downLoadList.contains(packageName)) {
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
}
|
||||
@@ -120,5 +120,23 @@ public class StorageUtils {
|
||||
return "" + (size) + "KB";
|
||||
}
|
||||
}
|
||||
//将字节数转化为MB
|
||||
public static String byteToMB(long size){
|
||||
long kb = 1024;
|
||||
long mb = kb*1024;
|
||||
long gb = mb*1024;
|
||||
if (size >= gb){
|
||||
return String.format("%.1f GB",(float)size/gb);
|
||||
}else if (size >= mb){
|
||||
float f = (float) size/mb;
|
||||
return String.format(f > 100 ?"%.0f MB":"%.1f MB",f);
|
||||
}else if (size > kb){
|
||||
float f = (float) size / kb;
|
||||
return String.format(f>100?"%.0f KB":"%.1f KB",f);
|
||||
}else {
|
||||
return String.format("%d B",size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -33,8 +33,11 @@ import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.appstore.uiui.R;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
@@ -49,103 +52,12 @@ import java.util.List;
|
||||
|
||||
public class Utils {
|
||||
|
||||
|
||||
public static final String PACKAGE = "appstore";
|
||||
public static final String DOWNLOAD_STARTALL_ACTION = PACKAGE + "_startall"; // 开始所有任务
|
||||
public static final String DOWNLOAD_DELETE_UPDATE_ACTION = PACKAGE + "_download_update_delete"; // 删除应用更新文件
|
||||
public static final String DOWNLOAD_DELETEALL_ACTION = PACKAGE + "_deleteall_alltask"; // 删除所有任务
|
||||
public static final String DOWNLOAD_ALLTASK_ACTION = PACKAGE + "_download_alltask"; // 获取所有任务
|
||||
public static final String DOWNLOAD_START_ACTION = PACKAGE + "_download_start"; // 下载标识
|
||||
public static final String DOWNLOAD_STOP_ACTION = PACKAGE + "_download_stop"; // 暂停标识
|
||||
public static final String DOWNLOAD_DELETE_PACKAGENAME_ACTION = PACKAGE + "_download_packagename_delete"; // 删除标识 根据包名
|
||||
public static final String DOWNLOAD_DELETE_URL_ACTION = PACKAGE + "_download_url_delete"; // 删除标识 根据下载地址
|
||||
public static final String DOWNLOAD_INITIALIZE_ACTION = PACKAGE + "_download_initialize"; // item初始化状态
|
||||
public static final String DOWNLOAD_PACKAGENAME_ACTION = PACKAGE + "_download_packagename"; // item初始化状态 包名
|
||||
public static final String DOWNLOAD_SERVICE_ACTION = PACKAGE + "_download_service"; // 下载状态回调服务
|
||||
|
||||
public static final String DOWNLOAD_ALLSERVICE_ACTION = PACKAGE + "_download_allservice"; // 返回所有下载任务
|
||||
public static final String DOWNLOAD_NEWSERVICE_ACTION = PACKAGE + "_download_newservice"; // 一个新的下载任务
|
||||
|
||||
// JPush 推送消息
|
||||
public static final String MESSAGE_RECEIVED_ACTION = "com.appstore.jpushdemo.MESSAGE_RECEIVED_ACTION";
|
||||
public static final String KEY_TITLE = "title"; // 消息标题
|
||||
public static final String KEY_MESSAGE = "message"; // 消息内容
|
||||
public static final String KEY_EXTRAS = "extras"; // 消息内容类型
|
||||
public static final String KEY_TYPE = "type"; // 消息内容类型
|
||||
|
||||
|
||||
public static final String ACTION_PACKAGE_REPLACED = PACKAGE + "PACKAGE_REPLACED"; // 替换应用
|
||||
public static final String ACTION_PACKAGE_REMOVED = PACKAGE + "PACKAGE_REMOVED"; // 卸载应用
|
||||
public static final String ACTION_PACKAGE_ADDED = PACKAGE + "PACKAGE_ADDED"; // 安装应用
|
||||
|
||||
// public static int[] babyImage = {R.drawable.language, R.drawable.habit, R.drawable.knowledge, R.drawable.security, R.drawable.promotion};
|
||||
// public static int[] childImage = {R.drawable.yuwen, R.drawable.shuxue, R.drawable.yingyu, R.drawable.qingshang, R.drawable.yishu, R.drawable.promotion};
|
||||
// public static int[] youngImage = {R.drawable.yuwen, R.drawable.shuxue, R.drawable.yingyu, R.drawable.promotion};
|
||||
// 学习日志上传标识
|
||||
public static final String APP_LRARNLOG = "com.colorflykids.alarm";
|
||||
// 学习日志下载标识
|
||||
public static final String APP_DOWNLOADLEARNLOG = "com.colorflykids.downloadlearnlog";
|
||||
// 账号注销标识
|
||||
public static final String APP_USERLOGOUT = "com.colorflykids.userlogout";
|
||||
|
||||
|
||||
public static final String UPDATE_SYSTEMUI = "cn.colorflykids.UPDATE_SYSTEMUI";
|
||||
public static final int COUNT_ONE_PAGE = 8;
|
||||
public static final int COUNT_ONE_PAGE2 = 10;
|
||||
public static final String YOUNGSYSTEM_APP_TONGBU = "com.school.app.syn"; // 小学系统 同步教材app
|
||||
/**
|
||||
*/
|
||||
public static final String number[] = {
|
||||
"1", "2", "3", "4", "5", "6", "7",
|
||||
"8", "9", "10", "0", "11"};
|
||||
public static final String STORE = "store";
|
||||
public static final String CATEGORY_THREE = "3";
|
||||
public static final String CATEGORY_SIX = "6";
|
||||
public static final String CATEGORY_UPSIX = "10";
|
||||
public static final String CLOSE_REST_WINDOW = "colse_rest_window";
|
||||
public static final String STOP_LOOPING_TIMER = "stop_looping_timer";
|
||||
public static final String START_LOOPING_TIMER = "start_looping_timer";
|
||||
public static String DOWNLOADAPP_CALLBACK = "com.colorflykids.downloadapp"; // 子界面下载回调 提示更新UI
|
||||
public static String MENU_YOUYOU = "youyou";
|
||||
public static String MENU_LANGUAGE = "语言启蒙";
|
||||
public static String MENU_HABIT = "行为习惯";
|
||||
public static String MENU_KNOWLEDGE = "生活认知";
|
||||
public static String MENU_SECURITY = "安全自理";
|
||||
public static String MENU_PROMOTION = "入园-综合提升";
|
||||
public static String MENU_LY = "优优乐园";
|
||||
public static String MENU_YW = "语文知识";
|
||||
public static String MENU_SX = "数理逻辑";
|
||||
public static String MENU_YY = "英语启蒙";
|
||||
public static String MENU_QS = "情商培养";
|
||||
public static String MENU_YS = "艺术提升";
|
||||
public static String MENU_ZH = "学前-综合提升";
|
||||
public static String MENU_TONGBUJIAOCAI = "同步教材";
|
||||
public static String MENU_YUWEN = "语文";
|
||||
public static String MENU_SHUXUE = "数学";
|
||||
public static String MENU_YINGYU = "英语";
|
||||
public static String MENU_ZONGHETISHEGN = "小学-综合提升";
|
||||
public static String[] babySystem = {MENU_LANGUAGE, MENU_HABIT, MENU_KNOWLEDGE, MENU_SECURITY, MENU_PROMOTION};
|
||||
public static String[] childSystem = {MENU_LY, MENU_YW, MENU_SX, MENU_YY, MENU_QS, MENU_YS, MENU_ZH};
|
||||
public static String[] youngSystem = {MENU_YUWEN, MENU_SHUXUE, MENU_YINGYU, MENU_ZONGHETISHEGN};
|
||||
|
||||
|
||||
public static String[] sonSystem = {MENU_HABIT, MENU_SECURITY, MENU_LANGUAGE, MENU_KNOWLEDGE, MENU_PROMOTION,
|
||||
MENU_LY, MENU_YW, MENU_SX, MENU_YY, MENU_QS, MENU_YS, MENU_ZH,
|
||||
MENU_TONGBUJIAOCAI, MENU_YUWEN, MENU_SHUXUE, MENU_YINGYU, MENU_YINGYU, MENU_ZONGHETISHEGN};
|
||||
public static String[][] tagList = {babySystem, childSystem, youngSystem};
|
||||
public static String subcategories[][] = {babySystem, childSystem, youngSystem};
|
||||
public static String system[] = {"入园系统", "学前系统", "小学系统"};
|
||||
public static String systemandno[] = {"入园系统", "学前系统", "小学系统", "未分配"};
|
||||
protected static Toast toast = null;
|
||||
private static String oldMsg;
|
||||
private static long oneTime = 0;
|
||||
private static long twoTime = 0;
|
||||
|
||||
|
||||
// 积分记录 达人标准次数记录
|
||||
|
||||
|
||||
|
||||
// MD5 设备地址标识
|
||||
// public static String getMAC(Context context) {
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // 如果当前设备系统大于等于6.0 使用下面的方法
|
||||
@@ -797,4 +709,7 @@ public class Utils {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
14
app/src/main/res/drawable/btn_shap_download.xml
Normal file
14
app/src/main/res/drawable/btn_shap_download.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 内部颜色 -->
|
||||
<solid
|
||||
android:color="@color/adapter_selector_default" />
|
||||
<!-- 圆角的幅度 -->
|
||||
<corners
|
||||
android:topLeftRadius="30dp"
|
||||
android:topRightRadius="30dp"
|
||||
android:bottomLeftRadius="30dp"
|
||||
android:bottomRightRadius="30dp" />
|
||||
|
||||
</shape>
|
||||
@@ -112,7 +112,8 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:overScrollMode="never"
|
||||
android:scrollbars="none">
|
||||
android:scrollbars="none"
|
||||
android:visibility="gone">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/detail_rv_image"
|
||||
@@ -131,6 +132,7 @@
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:text="应用介绍"
|
||||
android:textSize="@dimen/sp_16"
|
||||
android:visibility="gone"
|
||||
android:textStyle="bold">
|
||||
|
||||
</TextView>
|
||||
@@ -152,6 +154,7 @@
|
||||
android:layout_marginTop="@dimen/dp_2"
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:text="更新"
|
||||
android:visibility="gone"
|
||||
android:textSize="@dimen/sp_16"
|
||||
android:textStyle="bold">
|
||||
|
||||
@@ -175,6 +178,7 @@
|
||||
android:layout_marginTop="@dimen/dp_2"
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:text="信息"
|
||||
android:visibility="gone"
|
||||
android:textSize="@dimen/sp_16"
|
||||
android:textStyle="bold">
|
||||
|
||||
@@ -195,6 +199,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_15"
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:visibility="gone"
|
||||
android:text="版本" />
|
||||
|
||||
<TextView
|
||||
@@ -203,6 +208,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_15"
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:visibility="gone"
|
||||
android:text="时间" />
|
||||
|
||||
<TextView
|
||||
@@ -211,6 +217,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_15"
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:visibility="gone"
|
||||
android:text="开发者" />
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:visibility="gone"
|
||||
android:layout_weight="1">
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1.5"
|
||||
android:gravity="center_vertical"
|
||||
android:gravity="bottom"
|
||||
android:singleLine="true"
|
||||
android:text="今日头条"
|
||||
android:textColor="@color/black"
|
||||
@@ -48,6 +48,7 @@
|
||||
android:gravity="center_vertical"
|
||||
android:singleLine="true"
|
||||
android:text="北京字节跳动网络技术有限公司"
|
||||
android:visibility="gone"
|
||||
android:textSize="12sp" />
|
||||
|
||||
|
||||
@@ -78,7 +79,7 @@
|
||||
android:stateListAnimator="@null"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="10dp"
|
||||
android:background="@drawable/btn_style_none"
|
||||
android:background="@drawable/btn_shap_download"
|
||||
android:text="下载中"
|
||||
android:textSize="@dimen/sp_16"
|
||||
android:visibility="visible" />
|
||||
|
||||
@@ -112,7 +112,8 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:overScrollMode="never"
|
||||
android:scrollbars="none">
|
||||
android:scrollbars="none"
|
||||
android:visibility="gone">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/detail_rv_image"
|
||||
@@ -131,6 +132,7 @@
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:text="应用介绍"
|
||||
android:textSize="@dimen/sp_16"
|
||||
android:visibility="gone"
|
||||
android:textStyle="bold">
|
||||
|
||||
</TextView>
|
||||
@@ -153,6 +155,7 @@
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:text="更新"
|
||||
android:textSize="@dimen/sp_16"
|
||||
android:visibility="gone"
|
||||
android:textStyle="bold">
|
||||
|
||||
</TextView>
|
||||
@@ -176,6 +179,7 @@
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:text="信息"
|
||||
android:textSize="@dimen/sp_16"
|
||||
android:visibility="gone"
|
||||
android:textStyle="bold">
|
||||
|
||||
</TextView>
|
||||
@@ -195,6 +199,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_15"
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:visibility="gone"
|
||||
android:text="版本" />
|
||||
|
||||
<TextView
|
||||
@@ -203,6 +208,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_15"
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:visibility="gone"
|
||||
android:text="时间" />
|
||||
|
||||
<TextView
|
||||
@@ -211,6 +217,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_15"
|
||||
android:layout_marginRight="@dimen/dp_15"
|
||||
android:visibility="gone"
|
||||
android:text="开发者" />
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:visibility="gone"
|
||||
android:layout_weight="1">
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1.5"
|
||||
android:gravity="center_vertical"
|
||||
android:gravity="bottom"
|
||||
android:singleLine="true"
|
||||
android:text="今日头条"
|
||||
android:textColor="@color/black"
|
||||
@@ -48,6 +48,7 @@
|
||||
android:gravity="center_vertical"
|
||||
android:singleLine="true"
|
||||
android:text="北京字节跳动网络技术有限公司"
|
||||
android:visibility="gone"
|
||||
android:textSize="12sp" />
|
||||
|
||||
|
||||
@@ -78,7 +79,7 @@
|
||||
android:stateListAnimator="@null"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginRight="10dp"
|
||||
android:background="@drawable/btn_style_none"
|
||||
android:background="@drawable/btn_shap_download"
|
||||
android:text="下载中"
|
||||
android:textSize="@dimen/sp_16"
|
||||
android:visibility="visible" />
|
||||
|
||||
@@ -15,4 +15,6 @@
|
||||
<color name="search">#F1F1F1</color>
|
||||
<color name="red">#d64743</color>
|
||||
<color name="blue">#00a0e9</color>
|
||||
<color name="adapter_selector_default">#E9E9E9</color>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user