update:2020.12.25

fix:新后台对接完成
add:
This commit is contained in:
2020-12-25 11:08:25 +08:00
parent 67aa4fcf65
commit 80418ce5c3
50 changed files with 2589 additions and 1737 deletions

97
.gitignore vendored
View File

@@ -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 *.iml
.gradle .idea/workspace.xml
/local.properties .idea/tasks.xml
/.idea/caches .idea/gradle.xml
/.idea/libraries .idea/assetWizardSettings.xml
/.idea/modules.xml .idea/dictionaries
/.idea/workspace.xml .idea/libraries
/.idea/navEditor.xml # Android Studio 3 in .gitignore file.
/.idea/assetWizardSettings.xml .idea/caches
.DS_Store .idea/modules.xml
/build # Comment next line if keeping position of elements in Navigation Editor is relevant for you
/captures .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 .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
View File

@@ -84,3 +84,5 @@ lint/outputs/
lint/tmp/ lint/tmp/
# lint/reports/ # lint/reports/
/.idea/ /.idea/
/.idea/libraries/
/.idea/libraries/

View File

@@ -104,54 +104,44 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0' androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//github第三方控件 //github第三方控件
implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' 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:SmartRefreshLayout:1.1.0' //1.0.5及以前版本的老用户升级需谨慎API改动过大
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0' //没有使用特殊Header可以不加这行 implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0' //没有使用特殊Header可以不加这行
//glide
implementation 'com.github.bumptech.glide:glide:4.10.0' implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
//aria //aria
implementation 'com.arialyy.aria:core:3.7.7' implementation 'com.arialyy.aria:core:3.8.5'
annotationProcessor 'com.arialyy.aria:compiler:3.7.7' annotationProcessor 'com.arialyy.aria:compiler:3.8.5'
//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.hjq:xxpermissions:6.0' implementation 'com.hjq:xxpermissions:6.0'
//okhttp
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0' implementation 'com.squareup.okhttp3:okhttp:4.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0' //RxJava和Retrofit
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0' implementation 'io.reactivex.rxjava2:rxjava:2.2.5'
implementation 'io.reactivex:rxjava:1.2.2' implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex:rxandroid:1.2.1' 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:jpush:3.4.1' // 此处以JPush 3.4.1 版本为例。
implementation 'cn.jiguang.sdk:jcore:2.2.4' // 此处以JCore 2.2.4 版本为例。 implementation 'cn.jiguang.sdk:jcore:2.2.4' // 此处以JCore 2.2.4 版本为例。
//banner图
implementation 'com.zhpan.library:bannerview:2.6.4' 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' implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
//更换字体框架 //更换字体框架
} }
repositories { repositories {
mavenCentral() mavenCentral()

View File

@@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.appstore.uiui" package="com.appstore.uiui"
android:sharedUserId="android.uid.system"> android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" />
@@ -204,7 +203,7 @@
</intent-filter> </intent-filter>
</service> <!-- User defined. For test only 用户自定义的广播接收器 --> </service> <!-- User defined. For test only 用户自定义的广播接收器 -->
<receiver <receiver
android:name=".jpush.MyReceiver" android:name="com.appstore.uiui.jpush.MyReceiver"
android:enabled="true" android:enabled="true"
android:exported="false"> android:exported="false">
<intent-filter> <intent-filter>

View File

@@ -41,7 +41,7 @@
3、从3.4.1开始如果线程数为1文件初始化时将不再预占用对应长度的空间下载多少byte则占多大的空间 3、从3.4.1开始如果线程数为1文件初始化时将不再预占用对应长度的空间下载多少byte则占多大的空间
对于3.4.1之前版本的未完成的老任务,依然采用原来的文件空间占用方式; 对于3.4.1之前版本的未完成的老任务,依然采用原来的文件空间占用方式;
--> -->
<threadNum value="3"/> <threadNum value="1"/>
<!--设置下载队列最大任务数, 默认为2--> <!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="1"/> <maxTaskNum value="1"/>

View File

@@ -19,10 +19,7 @@ import com.appstore.uiui.utils.ApkUtils;
import com.appstore.uiui.utils.LogUtils; import com.appstore.uiui.utils.LogUtils;
import com.appstore.uiui.utils.SPUtils; import com.appstore.uiui.utils.SPUtils;
import com.appstore.uiui.utils.ToastUtil; import com.appstore.uiui.utils.ToastUtil;
import com.lzy.okgo.OkGo; import com.arialyy.aria.core.Aria;
import com.lzy.okgo.callback.FileCallback;
import com.lzy.okgo.model.Progress;
import com.lzy.okgo.model.Response;
import com.scwang.smartrefresh.layout.SmartRefreshLayout; import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator; import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator; import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
@@ -83,13 +80,14 @@ public class MyApplication extends Application {
JPushInterface.init(this); // 初始化 JPush JPushInterface.init(this); // 初始化 JPush
app = this; app = this;
ToastUtil.init(this); ToastUtil.init(this);
OkGo.getInstance().init(this) // OkGo.getInstance().init(this)
.setRetryCount(10)//重试次数 // .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)) { if (!isDebug(this)) {
catchException(); catchException();
} }
@@ -206,10 +204,10 @@ public class MyApplication extends Application {
setAppLockedstate(EXTRA); setAppLockedstate(EXTRA);
break; break;
case JIGUANG_FORCE_INSTALLAPK: case JIGUANG_FORCE_INSTALLAPK:
intallApk(EXTRA); // intallApk(EXTRA);
break; break;
case JIGUANG_FORCE_UNINSTALLAPK: case JIGUANG_FORCE_UNINSTALLAPK:
unintallApk(EXTRA); // unintallApk(EXTRA);
break; break;
} }
@@ -375,62 +373,62 @@ public class MyApplication extends Application {
} }
//静默安装应用使用okgo断网会出现问题等待修改使用aria //静默安装应用使用okgo断网会出现问题等待修改使用aria
synchronized private void intallApk(String jsondata) { // synchronized private void intallApk(String jsondata) {
try { // try {
JSONObject extra = new JSONObject(jsondata); // JSONObject extra = new JSONObject(jsondata);
final String packages = extra.getString("package"); // final String packages = extra.getString("package");
ToastUtil.debugShow("收到应用安装消息:包名" + packages); // ToastUtil.debugShow("收到应用安装消息:包名" + packages);
String url = extra.getString("url"); // String url = extra.getString("url");
OkGo.<File>get(url) // OkGo.<File>get(url)
.execute(new FileCallback() { // .execute(new FileCallback() {
@Override // @Override
public void onSuccess(final Response<File> response) { // public void onSuccess(final Response<File> response) {
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video"); //// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
new Thread(new Runnable() { // new Thread(new Runnable() {
@Override // @Override
public void run() { // public void run() {
ApkUtils.installApp(app.getAppContext(), response.body().getAbsolutePath()); // ApkUtils.installApp(app.getAppContext(), response.body().getAbsolutePath());
} // }
}).start(); // }).start();
LogUtils.e("onSuccess", "download file successful,now installing"); // 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 // synchronized private void unintallApk(String json) {
public void onError(Response<File> response) { // String sn_id = (String) SPUtils.get(getApplicationContext(), "sn_id", "-1");
super.onError(response); // try {
LogUtils.e("manageCustomMessage", "File download Failure"); // JSONObject object = new JSONObject(json);
} // String packageName = object.getString("package");
// ToastUtil.debugShow("收到应用卸载消息:包名" + packageName);
@Override // if (!packageName.equals("") && !packageName.equals(getApplicationContext().getPackageName())) {
public void downloadProgress(Progress progress) { // if (!ApkUtils.isAvailable(getApplicationContext(), packageName)) {
super.downloadProgress(progress); // OKGO.setAppuninstallInfo(sn_id, packageName);
LogUtils.e("downloadProgress", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed); // } else {
} // ApkUtils.deleteApkInSilence(packageName);
}); // }
// }
} catch (JSONException e) { // } catch (JSONException e) {
e.printStackTrace(); // e.printStackTrace();
LogUtils.e("intallApk", e.getMessage()); // 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());
}
}
} }

View File

@@ -4,6 +4,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
@@ -13,6 +14,8 @@ import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.appstore.uiui.R; import com.appstore.uiui.R;
import com.appstore.uiui.adapter.ImageAdapter; import com.appstore.uiui.adapter.ImageAdapter;
import com.appstore.uiui.base.BaseActivity; 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.bean.GlideCircleWithBorder;
import com.appstore.uiui.helper.CustomSnapHelper; import com.appstore.uiui.helper.CustomSnapHelper;
import com.appstore.uiui.utils.ApkUtils; 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.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.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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@@ -67,26 +71,27 @@ public class DetailsActivity extends BaseActivity {
@Override @Override
protected void initData() { protected void initData() {
Aria.download(this).register();
appInfo = (AppInfo) getIntent().getSerializableExtra("appinfo"); appInfo = (AppInfo) getIntent().getSerializableExtra("appinfo");
if (appInfo == null) { if (appInfo == null) {
ToastUtil.show("获取引用信息失败,返回重试"); ToastUtil.show("获取引用信息失败,返回重试");
return; return;
} }
final DownloadTask downloadTask = OkDownload.getInstance().getTask(appInfo.getApp_url()); // final DownloadTask downloadTask = OkDownload.getInstance().getTask(appInfo.getApp_url());
if (downloadTask != null) { // if (downloadTask != null) {
downloadTask.register(new FileDownloadListener(appInfo.getApp_url())); // downloadTask.register(new FileDownloadListener(appInfo.getApp_url()));
refresh(downloadTask.progress); // refresh(downloadTask.progress);
} // }
// tv_title.setText(appInfo.getApp_name()); // tv_title.setText(appInfo.getApp_name());
tv_name.setText(appInfo.getApp_name()); tv_name.setText(appInfo.getApp_name());
tv_company.setText(appInfo.getApp_developer()); 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()); detail_tv_Developers.setText("开发者\t" + appInfo.getApp_developer());
tv_update_time.setText("时间\t" + appInfo.getCreatetime()); tv_update_time.setText("时间\t" + appInfo.getCreatetime());
tv_version.setText("版本\t" + appInfo.getApp_version_name()); tv_version.setText("版本\t" + appInfo.getApp_version_name());
tv_content.setText(appInfo.getApp_desc()); tv_content.setText(appInfo.getApp_desc());
rating_bar.setRating((float) appInfo.getApp_score()); 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); .into(iv_icon);
List<String> list = new ArrayList<String>() {{ List<String> list = new ArrayList<String>() {{
this.add(appInfo.getApp_preview1()); this.add(appInfo.getApp_preview1());
@@ -98,34 +103,91 @@ public class DetailsActivity extends BaseActivity {
rv_image.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)); rv_image.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
CustomSnapHelper snapHelper = new CustomSnapHelper(); CustomSnapHelper snapHelper = new CustomSnapHelper();
snapHelper.attachToRecyclerView(rv_image); snapHelper.attachToRecyclerView(rv_image);
if (appInfo.isInstall()) { final boolean installed = ApkUtils.isInstalled(DetailsActivity.this, appInfo.getApp_package());
if (appInfo.isUpdate()) { final boolean update = ApkUtils.isUpdate(DetailsActivity.this, appInfo.getApp_package(), appInfo.getApp_version_code());
tv_download.setText("更新" + "(" + appInfo.getApp_size() + "MB" + ")"); if (installed) {
if (update) {
tv_download.setText("更新" + "(" + StorageUtils.byteToMB(appInfo.getApp_size()) + ")");
} else { } else {
tv_download.setText("打开"); tv_download.setText("打开");
} }
} else { } else {
tv_download.setText("安装" + "(" + appInfo.getApp_size() + "MB" + ")"); tv_download.setText("安装" + "(" + StorageUtils.byteToMB(appInfo.getApp_size()) + ")");
} }
tv_download.setOnClickListener(new View.OnClickListener() { tv_download.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (appInfo.isInstall() && !appInfo.isUpdate()) { if (installed && !update) {
ApkUtils.openApp(DetailsActivity.this, appInfo.getApp_package()); ApkUtils.openApp(DetailsActivity.this, appInfo.getApp_package());
} else { } else {
GetRequest<File> request = OkGo.get(appInfo.getApp_url()); // GetRequest<File> request = OkGo.get(appInfo.getApp_url());
//这里第一个参数是tag代表下载任务的唯一标识传任意字符串都行需要保证唯一,我这里用url作为了tag // //这里第一个参数是tag代表下载任务的唯一标识传任意字符串都行需要保证唯一,我这里用url作为了tag
OkDownload.request(appInfo.getApp_url(), request)// // OkDownload.request(appInfo.getApp_url(), request)//
// .priority(apk.priority)// //// .priority(apk.priority)//
.extra1(appInfo)// // .extra1(appInfo)//
.save()// // .save()//
.register(new FileDownloadListener(appInfo.getApp_url()))// // .register(new FileDownloadListener(appInfo.getApp_url()))//
.start(); // .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 @Override
protected void setListener() { protected void setListener() {
if (myReceiver == null) { if (myReceiver == null) {
@@ -143,71 +205,71 @@ public class DetailsActivity extends BaseActivity {
finish(); finish();
} }
public void refresh(Progress progress) { // public void refresh(Progress progress) {
switch (progress.status) { // switch (progress.status) {
case Progress.NONE: // case Progress.NONE:
tv_download.setText("安装" + "(" + appInfo.getApp_size() + "MB" + ")"); // tv_download.setText("安装" + "(" + appInfo.getApp_size() + "MB" + ")");
break; // break;
case Progress.PAUSE: // case Progress.PAUSE:
tv_download.setText("继续"); // tv_download.setText("继续");
break; // break;
case Progress.ERROR: // case Progress.ERROR:
tv_download.setText("出错"); // tv_download.setText("出错");
break; // break;
case Progress.WAITING: // case Progress.WAITING:
tv_download.setText("等待"); // tv_download.setText("等待");
break; // break;
case Progress.LOADING: // case Progress.LOADING:
tv_download.setText((int) (progress.fraction * 100) + "%"); // tv_download.setText((int) (progress.fraction * 100) + "%");
break; // break;
case Progress.FINISH: // case Progress.FINISH:
tv_download.setText("安装中"); // tv_download.setText("安装中");
break; // break;
} // }
} // }
class FileDownloadListener extends DownloadListener { // class FileDownloadListener extends DownloadListener {
//
public FileDownloadListener(Object tag) { // public FileDownloadListener(Object tag) {
super(tag); // super(tag);
} // }
//
@Override // @Override
public void onStart(Progress progress) { // public void onStart(Progress progress) {
//
} // }
//
@Override // @Override
public void onProgress(Progress progress) { // public void onProgress(Progress progress) {
if (tag == appInfo.getApp_url()) { // if (tag == appInfo.getApp_url()) {
refresh(progress); // refresh(progress);
} // }
} // }
//
@Override // @Override
public void onError(Progress progress) { // public void onError(Progress progress) {
Throwable throwable = progress.exception; // Throwable throwable = progress.exception;
if (throwable != null) throwable.printStackTrace(); // if (throwable != null) throwable.printStackTrace();
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败请重试"); // ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败请重试");
} // }
//
@Override // @Override
public void onFinish(final File file, Progress progress) { // public void onFinish(final File file, Progress progress) {
tv_download.setText("安装中"); // tv_download.setText("安装中");
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成"); // ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成");
new Thread(new Runnable() { // new Thread(new Runnable() {
@Override // @Override
public void run() { // public void run() {
ApkUtils.installApp(DetailsActivity.this, file.getAbsolutePath()); // ApkUtils.installApp(DetailsActivity.this, file.getAbsolutePath());
} // }
}).start(); // }).start();
} // }
//
@Override // @Override
public void onRemove(Progress progress) { // public void onRemove(Progress progress) {
//
} // }
} // }
public class installReceiver extends BroadcastReceiver { public class installReceiver extends BroadcastReceiver {
@Override @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")) { if (action.equals("com.appstore.uiui.PACKAGE_ADDED") || action.equals("com.appstore.uiui.PACKAGE_REPLACED")) {
String packageName = intent.getStringExtra("package"); String packageName = intent.getStringExtra("package");
if (packageName.equalsIgnoreCase(appInfo.getApp_package())) { if (packageName.equalsIgnoreCase(appInfo.getApp_package())) {
appInfo.setInstall(true);
tv_download.setText("打开"); tv_download.setText("打开");
} }
} }
@@ -230,6 +291,54 @@ public class DetailsActivity extends BaseActivity {
super.onDestroy(); super.onDestroy();
if (myReceiver != null) { if (myReceiver != null) {
unregisterReceiver(myReceiver); 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);
}
} }

View File

@@ -3,7 +3,6 @@ package com.appstore.uiui.activity;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.view.View; import android.view.View;
import android.widget.Adapter;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@@ -11,23 +10,14 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.appstore.uiui.R; import com.appstore.uiui.R;
import com.appstore.uiui.adapter.AppAdapter;
import com.appstore.uiui.adapter.DownloadManagerAdapter; import com.appstore.uiui.adapter.DownloadManagerAdapter;
import com.appstore.uiui.base.BaseActivity; 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.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 RecyclerView recyclerView;
private DownloadManagerAdapter adapter; private DownloadManagerAdapter adapter;
private OkDownload okDownload; // private OkDownload okDownload;
private ImageView iv_notask; private ImageView iv_notask;
@Override @Override
@@ -44,11 +34,12 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
@Override @Override
protected void initData() { protected void initData() {
okDownload = OkDownload.getInstance(); // okDownload = OkDownload.getInstance();
adapter = new DownloadManagerAdapter(this, handler); adapter = new DownloadManagerAdapter(this, handler);
adapter.updateData(DownloadManagerAdapter.TYPE_ING); // adapter.updateData(DownloadManagerAdapter.TYPE_ING);
recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
adapter.updateNotCompleteTask();
if (adapter.getItemCount() == 0) { if (adapter.getItemCount() == 0) {
iv_notask.setVisibility(View.VISIBLE); iv_notask.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE); recyclerView.setVisibility(View.GONE);
@@ -56,7 +47,7 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
iv_notask.setVisibility(View.GONE); iv_notask.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE); recyclerView.setVisibility(View.VISIBLE);
} }
okDownload.addOnAllTaskEndListener(this); // okDownload.addOnAllTaskEndListener(this);
} }
@Override @Override
@@ -65,18 +56,18 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
} }
@Override // @Override
public void onAllTaskEnd() { // public void onAllTaskEnd() {
ToastUtil.show("所有任务已完成"); // ToastUtil.show("所有任务已完成");
adapter.notifyDataSetChanged(); // adapter.notifyDataSetChanged();
//
} // }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
okDownload.removeOnAllTaskEndListener(this); // okDownload.removeOnAllTaskEndListener(this);
adapter.unRegister(); // adapter.unRegister();
} }
@Override @Override
@@ -94,7 +85,7 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
public void handleMessage(@NonNull Message msg) { public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg); super.handleMessage(msg);
if (msg.what == 100) { if (msg.what == 100) {
adapter.updateData(DownloadManagerAdapter.TYPE_ING); // adapter.updateData(DownloadManagerAdapter.TYPE_ING);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
if (adapter.getItemCount() == 0) { if (adapter.getItemCount() == 0) {
iv_notask.setVisibility(View.VISIBLE); iv_notask.setVisibility(View.VISIBLE);

View File

@@ -29,7 +29,8 @@ import java.util.List;
public class KindDetailActivity extends BaseActivity implements RefreshManager.RefreshInterface { public class KindDetailActivity extends BaseActivity implements RefreshManager.RefreshInterface {
private TextView title; private TextView title;
private String name; private String name;
private int subject, grade, type = 0; private int subject, type = 0;
private String grade;
private SmartRefreshLayout mRefreshLayout; private SmartRefreshLayout mRefreshLayout;
private RecyclerView detail_rv; private RecyclerView detail_rv;
private AppAdapter adapter; private AppAdapter adapter;
@@ -57,10 +58,10 @@ public class KindDetailActivity extends BaseActivity implements RefreshManager.R
if (name.equals("娱乐")) { if (name.equals("娱乐")) {
type = 1; type = 1;
} }
grade = (int) SPUtils.get(this, "sn_grade", 0); grade = (String) SPUtils.get(this, "sn_grade", "");
title.setText(name); title.setText(name);
RefreshManager.getInstance().register(this); RefreshManager.getInstance().register(this);
adapter = new AppAdapter(AppInfoList, false, getApplicationContext()); adapter = new AppAdapter(AppInfoList, KindDetailActivity.this);
adapter.setHasStableIds(true); adapter.setHasStableIds(true);
detail_rv.setAdapter(adapter); detail_rv.setAdapter(adapter);
detail_rv.setLayoutManager(new LinearLayoutManager(this)); detail_rv.setLayoutManager(new LinearLayoutManager(this));
@@ -69,10 +70,10 @@ public class KindDetailActivity extends BaseActivity implements RefreshManager.R
mRefreshLayout.setOnRefreshListener(new OnRefreshListener() { mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override @Override
public void onRefresh(RefreshLayout refreshlayout) { 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 @Override
@@ -91,7 +92,7 @@ public class KindDetailActivity extends BaseActivity implements RefreshManager.R
switch (msg.what) { switch (msg.what) {
case 1: case 1:
AppInfoList = (List<AppInfo>) msg.obj; AppInfoList = (List<AppInfo>) msg.obj;
adapter.setData(checkUpdateOrInstalled(AppInfoList)); adapter.setData(AppInfoList);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
mImageView.setVisibility(View.GONE); mImageView.setVisibility(View.GONE);
detail_rv.setVisibility(View.VISIBLE); 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 @Override
public void onRefresh() { public void onRefresh() {
@@ -123,4 +117,6 @@ public class KindDetailActivity extends BaseActivity implements RefreshManager.R
public void onLoadBitMap(boolean isLoad) { public void onLoadBitMap(boolean isLoad) {
} }
} }

View File

@@ -26,15 +26,19 @@ import androidx.viewpager.widget.ViewPager;
import com.appstore.uiui.R; import com.appstore.uiui.R;
import com.appstore.uiui.base.BaseActivity; 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.FeaturedFragment;
import com.appstore.uiui.fragment.KindFragment; import com.appstore.uiui.fragment.KindFragment;
import com.appstore.uiui.fragment.ManageFragment; import com.appstore.uiui.fragment.ManageFragment;
import com.appstore.uiui.fragment.RankFragment;
import com.appstore.uiui.jpush.ExampleUtil; import com.appstore.uiui.jpush.ExampleUtil;
import com.appstore.uiui.jpush.LocalBroadcastManager; import com.appstore.uiui.jpush.LocalBroadcastManager;
import com.appstore.uiui.jpush.TagAliasOperatorHelper; import com.appstore.uiui.jpush.TagAliasOperatorHelper;
import com.appstore.uiui.network.NetWorkManager;
import com.appstore.uiui.network.OKGO; 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.service.MyDownloadService;
import com.appstore.uiui.utils.ApkUtils; import com.appstore.uiui.utils.ApkUtils;
import com.appstore.uiui.utils.LogUtils; import com.appstore.uiui.utils.LogUtils;
@@ -45,10 +49,6 @@ import com.flyco.tablayout.SlidingTabLayout;
import com.hjq.permissions.OnPermission; import com.hjq.permissions.OnPermission;
import com.hjq.permissions.Permission; import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions; 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@@ -56,6 +56,10 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import cn.jpush.android.api.JPushInterface; 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_ADD;
import static com.appstore.uiui.jpush.TagAliasOperatorHelper.ACTION_CHECK; import static com.appstore.uiui.jpush.TagAliasOperatorHelper.ACTION_CHECK;
@@ -78,7 +82,7 @@ public class MainActivity extends BaseActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.e("MainActivity","onCreate"); Log.e("MainActivity", "onCreate");
requestPermission(); requestPermission();
registerMessageReceiver(); // used for receive msg registerMessageReceiver(); // used for receive msg
String rid = JPushInterface.getRegistrationID(getApplicationContext()); String rid = JPushInterface.getRegistrationID(getApplicationContext());
@@ -90,7 +94,9 @@ public class MainActivity extends BaseActivity {
// ToastUtil.show("Get registration fail, JPush init failed!"); // ToastUtil.show("Get registration fail, JPush init failed!");
// Toast.makeText(this, "Get registration fail, JPush init failed!", Toast.LENGTH_SHORT).show(); // Toast.makeText(this, "Get registration fail, JPush init failed!", Toast.LENGTH_SHORT).show();
} }
OKGO.getUserInfo(handler); // OKGO.getUserInfo(handler);
getUserInfo();
// PackageManager pm = getPackageManager(); // PackageManager pm = getPackageManager();
// pm.setApplicationEnabledSetting("com.tencent.qqmusic", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0); // pm.setApplicationEnabledSetting("com.tencent.qqmusic", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
startService(new Intent(MainActivity.this, MyDownloadService.class)); startService(new Intent(MainActivity.this, MyDownloadService.class));
@@ -105,12 +111,13 @@ public class MainActivity extends BaseActivity {
@Override @Override
public void onConfigurationChanged(@NonNull Configuration newConfig) { public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
Log.e("MainActivity","onConfigurationChanged"); Log.e("MainActivity", "onConfigurationChanged");
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(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<>(); final List<Fragment> fragmentList = new ArrayList<>();
fragmentList.add(new FeaturedFragment()); fragmentList.add(new FeaturedFragment());
// fragmentList.add(new RankFragment()); // fragmentList.add(new RankFragment());
fragmentList.add(new KindFragment()); // fragmentList.add(new KindFragment());
fragmentList.add(new ManageFragment()); fragmentList.add(new ManageFragment());
mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override @Override
@@ -160,13 +167,14 @@ public class MainActivity extends BaseActivity {
} }
}); });
mViewPager.setOffscreenPageLimit(3); mViewPager.setOffscreenPageLimit(3);
String titles[] = new String[]{"专属应用", "我的分类", "下载管理"}; String titles[] = new String[]{"专属应用",/* "我的分类",*/ "下载管理"};
mSlidingTabLayout.setViewPager(mViewPager, titles); mSlidingTabLayout.setViewPager(mViewPager, titles);
} }
@Override @Override
protected void initData() { protected void initData() {
OKGO.getAllAppPackageName(handler); // OKGO.getAllAppPackageName(handler);
getAllAppPackageName();
} }
@Override @Override
@@ -184,9 +192,9 @@ public class MainActivity extends BaseActivity {
e.printStackTrace(); e.printStackTrace();
} }
if (null != packageInfo) { if (null != packageInfo) {
OKGO.checkUpdateByPackage(handler, packageInfo.packageName, String.valueOf(packageInfo.versionCode)); // OKGO.checkUpdateByPackage(handler, packageInfo.packageName, String.valueOf(packageInfo.versionCode));
} else { } 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() { private Handler handler = new Handler() {
@Override @Override
public void handleMessage(@NonNull Message msg) { public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg); super.handleMessage(msg);
switch (msg.what) { switch (msg.what) {
case 0: // case 0:
SPUtils.put(MainActivity.this, "isLogined", 0); // SPUtils.put(MainActivity.this, "isLogined", 0);
break; // break;
case 1: // case 1:
SPUtils.put(MainActivity.this, "isLogined", 1); // SPUtils.put(MainActivity.this, "isLogined", 1);
UserInfo userInfo = (UserInfo) msg.obj; // UserInfo userInfo = (UserInfo) msg.obj;
SPUtils.put(MainActivity.this, "member_id", userInfo.getMember_id()); // SPUtils.put(MainActivity.this, "member_id", userInfo.getMember_id());
SPUtils.put(MainActivity.this, "sn_id", userInfo.getId()); // SPUtils.put(MainActivity.this, "sn_id", userInfo.getId());
SPUtils.put(MainActivity.this, "sn_grade", userInfo.getSn_grade()); // SPUtils.put(MainActivity.this, "sn_grade", userInfo.getGrade());
break; // break;
case 2: // case 2:
SPUtils.put(MainActivity.this, "isLogined", 2); // SPUtils.put(MainActivity.this, "isLogined", 2);
break; // break;
case 200: case 200:
String url = (String) msg.obj; String url = (String) msg.obj;
getFile(url); // getFile(url);
break; break;
case 201: case 201:
String apppackage = (String) msg.obj; String apppackage = (String) msg.obj;
@@ -413,7 +504,6 @@ public class MainActivity extends BaseActivity {
if (Settings.System.putString(getContentResolver(), "qch_app_forbid", apppackage)) { if (Settings.System.putString(getContentResolver(), "qch_app_forbid", apppackage)) {
Log.e("fht", "app package write successful"); Log.e("fht", "app package write successful");
} }
break; break;
case 202: case 202:
break; break;
@@ -421,32 +511,32 @@ public class MainActivity extends BaseActivity {
} }
}; };
private void getFile(String url) { // private void getFile(String url) {
OkGo.<File>get(url) // OkGo.<File>get(url)
.execute(new FileCallback() { // .execute(new FileCallback() {
@Override // @Override
public void onSuccess(final Response<File> response) { // public void onSuccess(final Response<File> response) {
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video"); //// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
new Thread(new Runnable() { // new Thread(new Runnable() {
@Override // @Override
public void run() { // public void run() {
ApkUtils.installApp(MainActivity.this, response.body().getAbsolutePath()); // ApkUtils.installApp(MainActivity.this, response.body().getAbsolutePath());
} // }
}).start(); // }).start();
LogUtils.e("getFile", "download file successful,now installing"); // LogUtils.e("getFile", "download file successful,now installing");
} // }
//
@Override // @Override
public void onError(Response<File> response) { // public void onError(Response<File> response) {
super.onError(response); // super.onError(response);
LogUtils.e("getFile", "File download Failure"); // LogUtils.e("getFile", "File download Failure");
} // }
//
@Override // @Override
public void downloadProgress(Progress progress) { // public void downloadProgress(Progress progress) {
super.downloadProgress(progress); // super.downloadProgress(progress);
LogUtils.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed); // LogUtils.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
} // }
}); // });
} // }
} }

View File

@@ -47,7 +47,7 @@ public class SearcherActivity extends BaseActivity {
@Override @Override
protected void initData() { protected void initData() {
madapter = new AppAdapter(mAppInfoList, false, getApplicationContext()); madapter = new AppAdapter(mAppInfoList, SearcherActivity.this);
madapter.setHasStableIds(true); madapter.setHasStableIds(true);
recyclerView.setAdapter(madapter); recyclerView.setAdapter(madapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setLayoutManager(new LinearLayoutManager(this));
@@ -59,7 +59,7 @@ public class SearcherActivity extends BaseActivity {
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
LogUtils.e("icon_serach", query); LogUtils.e("icon_serach", query);
OKGO.searchAppbyName(handler, query); // OKGO.searchAppbyName(handler, query);
return false; return false;
} }
@@ -83,18 +83,11 @@ public class SearcherActivity extends BaseActivity {
switch (msg.what) { switch (msg.what) {
case 1: case 1:
mAppInfoList = (List<AppInfo>) msg.obj; mAppInfoList = (List<AppInfo>) msg.obj;
madapter.setData(checkUpdateOrInstalled(mAppInfoList)); madapter.setData(mAppInfoList);
madapter.notifyDataSetChanged(); madapter.notifyDataSetChanged();
break; 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;
}
} }

View File

@@ -2,8 +2,6 @@ package com.appstore.uiui.adapter;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -14,20 +12,22 @@ import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.appstore.uiui.R; import com.appstore.uiui.R;
import com.appstore.uiui.activity.DetailsActivity; import com.appstore.uiui.activity.DetailsActivity;
import com.appstore.uiui.base.FilePath;
import com.appstore.uiui.bean.AppInfo; 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.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.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.io.File;
import java.util.List; import java.util.List;
@@ -39,19 +39,15 @@ import java.util.List;
public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> { public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
private List<AppInfo> mAppInfoList; private List<AppInfo> mAppInfoList;
private Context mContext; private Context mContext;
private DownloadTask mDownloadTask;
private boolean isShowOrder;
private boolean isNotLoadBitmap = false;
//order代表是否显示所在的位置1.2.3. //order代表是否显示所在的位置1.2.3.
public AppAdapter(List<AppInfo> appInfoList, boolean isShowOrder, Context context) {
public AppAdapter(List<AppInfo> appInfoList, Context context) {
this.mContext = context; this.mContext = context;
this.mAppInfoList = appInfoList; this.mAppInfoList = appInfoList;
this.isShowOrder = isShowOrder;
} }
@Override @Override
@@ -61,41 +57,18 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
} }
@Override @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 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) Glide.with(mContext)
.asBitmap() .asBitmap()
.load(appInfo.getApp_img()) .load(appInfo.getApp_img())
.placeholder(R.drawable.ic_place_holder) // .placeholder(R.drawable.ic_place_holder)
.transform(new GlideCircleWithBorder(mContext)) // .transform(new GlideCircleWithBorder(mContext))
.into(holder.ivIcon); .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()); holder.tvCompany.setText(appInfo.getApp_developer());
if (isShowOrder) {
holder.tvName.setText((position + 1) + "." + appInfo.getApp_name());
} else {
holder.tvName.setText(appInfo.getApp_name()); holder.tvName.setText(appInfo.getApp_name());
} holder.tvSize.setText(StorageUtils.byteToMB(appInfo.getApp_size()));
holder.tvSize.setText(appInfo.getApp_size() + "M");
holder.ratingBar.setRating((float) appInfo.getApp_score()); holder.ratingBar.setRating((float) appInfo.getApp_score());
holder.itemView.setOnClickListener(new View.OnClickListener() { holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
@@ -106,49 +79,83 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
mContext.startActivity(intent); mContext.startActivity(intent);
} }
}); });
final boolean installed = ApkUtils.isInstalled(mContext, appInfo.getApp_package());
if (appInfo.isInstall()) { final boolean update = ApkUtils.isUpdate(mContext, appInfo.getApp_package(), appInfo.getApp_version_code());
if (appInfo.isUpdate()) { if (installed) {
if (update) {
holder.btnDownLoad.setText("更新"); holder.btnDownLoad.setText("更新");
holder.btnDownLoad.setTextColor(mContext.getColor(R.color.default_color)); 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 { } else {
holder.btnDownLoad.setText("打开"); holder.btnDownLoad.setText("打开");
holder.btnDownLoad.setTextColor(mContext.getColor(R.color.default_color)); 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 { } else {
holder.btnDownLoad.setText("安装"); holder.btnDownLoad.setText("安装");
holder.btnDownLoad.setTextColor(mContext.getColor(R.color.default_color)); 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));
if (downloadTask != null) { if (null != mDownloadTask) {
holder.refresh(downloadTask.progress); 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() { holder.btnDownLoad.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (appInfo.isInstall() && !appInfo.isUpdate()) { if (installed && !update) {
ApkUtils.openApp(mContext, appInfo.getApp_package()); ApkUtils.openApp(mContext, appInfo.getApp_package());
} else { } 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 @Override
public int getItemCount() { public int getItemCount() {
return mAppInfoList == null ? 0 : mAppInfoList.size(); return mAppInfoList == null ? 0 : mAppInfoList.size();
@@ -165,10 +172,6 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
TextView tvCompany, tvName, tvSize; TextView tvCompany, tvName, tvSize;
Button btnDownLoad; Button btnDownLoad;
RatingBar ratingBar; RatingBar ratingBar;
// TextView tvInstalled;
private DownloadTask task;
private String tag;
public Holder(View itemView) { public Holder(View itemView) {
super(itemView); super(itemView);
@@ -178,54 +181,65 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
tvSize = itemView.findViewById(R.id.app_tv_size); tvSize = itemView.findViewById(R.id.app_tv_size);
btnDownLoad = itemView.findViewById(R.id.app_btn_download); btnDownLoad = itemView.findViewById(R.id.app_btn_download);
ratingBar = itemView.findViewById(R.id.app_rating_bar); ratingBar = itemView.findViewById(R.id.app_rating_bar);
// tvInstalled = itemView.findViewById(R.id.app_tv_installed);
} }
public void bind() { void refresh(DownloadTask task) {
switch (task.getState()) {
} case IEntity.STATE_OTHER:
void refresh(Progress progress) {
switch (progress.status) {
case Progress.NONE:
btnDownLoad.setText("安装"); btnDownLoad.setText("安装");
break; break;
case Progress.PAUSE: case IEntity.STATE_FAIL:
btnDownLoad.setText("继续");
break;
case Progress.ERROR:
btnDownLoad.setText("出错"); btnDownLoad.setText("出错");
break; break;
case Progress.WAITING: case IEntity.STATE_COMPLETE:
btnDownLoad.setText("安装");
break;
case IEntity.STATE_STOP:
btnDownLoad.setText("继续");
break;
case IEntity.STATE_WAIT:
btnDownLoad.setText("等待"); btnDownLoad.setText("等待");
break; break;
case Progress.FINISH: case IEntity.STATE_RUNNING:
btnDownLoad.setText("安装中"); btnDownLoad.setText(task.getPercent() + "%");
break; break;
case Progress.LOADING: case IEntity.STATE_PRE:
btnDownLoad.setText((int) (progress.fraction * 100) + "%"); break;
case IEntity.STATE_POST_PRE:
break;
case IEntity.STATE_CANCEL:
break; break;
} }
} }
void setTask(DownloadTask task) { void refreshEntity(DownloadEntity entity) {
this.task = task; switch (entity.getState()) {
} case IEntity.STATE_OTHER:
btnDownLoad.setText("安装");
void setTag(String tag) { break;
this.tag = tag; case IEntity.STATE_FAIL:
} btnDownLoad.setText("出错");
break;
String getTag() { case IEntity.STATE_COMPLETE:
return tag; 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) { public void setData(List<AppInfo> appInfos) {
@@ -233,49 +247,105 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
notifyDataSetChanged(); 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; private void ItemChanged(DownloadTask task) {
mDownloadTask = task;
ListDownloadListener(Object tag, Holder holder) { // notifyDataSetChanged();
super(tag); for (int i = 0; i < mAppInfoList.size(); i++) {
this.holder = holder; 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 @Download.onTaskRunning
public void onError(Progress progress) { void onTaskRunning(DownloadTask task) {
Throwable throwable = progress.exception; ItemChanged(task);
if (throwable != null) throwable.printStackTrace();
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败请重试");
} }
@Override @Download.onTaskComplete
public void onFinish(final File file, Progress progress) { void onTaskComplete(DownloadTask task) {
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成"); ItemChanged(task);
new Thread(new Runnable() {
@Override
public void run() {
ApkUtils.installApp(mContext, file.getAbsolutePath());
}
}).start();
} }
@Override @Download.onWait
public void onRemove(Progress progress) { 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);
}
} }

View File

@@ -2,33 +2,32 @@ package com.appstore.uiui.adapter;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.text.format.Formatter;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.appstore.uiui.R; import com.appstore.uiui.R;
import com.appstore.uiui.bean.AppInfo; import com.appstore.uiui.utils.ApkUtils;
import com.appstore.uiui.bean.GlideCircleWithBorder; import com.appstore.uiui.utils.FileUtils;
import com.appstore.uiui.listener.LogDownloadListener; import com.appstore.uiui.utils.Utils;
import com.appstore.uiui.view.NumberProgressBar; 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.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.io.File;
import java.util.List; import java.util.List;
import java.util.Map;
public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManagerAdapter.Holder> { 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; public static final int TYPE_ING = 2;
private Context mContext; private Context mContext;
private List<DownloadTask> values; private List<DownloadEntity> mEntityList;
private int type; private DownloadTask mDownloadTask;
private final LayoutInflater mInflater; private final LayoutInflater mInflater;
private Handler mhandler; private Handler mhandler;
@@ -50,14 +49,25 @@ public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManager
this.mhandler = handler; this.mhandler = handler;
} }
public void updateData(int type) {
//这里是将数据库的数据恢复 // public void updateData(int type) {
this.type = type; // //这里是将数据库的数据恢复
if (type == TYPE_ALL) values = OkDownload.restore(DownloadManager.getInstance().getAll()); // this.type = type;
if (type == TYPE_FINISH) // if (type == TYPE_ALL) values = OkDownload.restore(DownloadManager.getInstance().getAll());
values = OkDownload.restore(DownloadManager.getInstance().getFinished()); // if (type == TYPE_FINISH)
if (type == TYPE_ING) // values = OkDownload.restore(DownloadManager.getInstance().getFinished());
values = OkDownload.restore(DownloadManager.getInstance().getDownloading()); // 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(); notifyDataSetChanged();
} }
@@ -70,40 +80,80 @@ public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManager
@Override @Override
public void onBindViewHolder(@NonNull Holder holder, int position) { public void onBindViewHolder(@NonNull Holder holder, int position) {
DownloadTask task = values.get(position); Aria.download(this).register();
String tag = createTag(task); final DownloadEntity entity = mEntityList.get(position);
task.register(new ListDownloadListener(tag, holder))// // DownloadTask task = values.get(position);
.register(new LogDownloadListener()); // String tag = createTag(task);
holder.setTag(tag); // task.register(new ListDownloadListener(tag, holder))//
holder.setTask(task); // .register(new LogDownloadListener());
holder.bind(); // holder.setTag(tag);
holder.refresh(task.progress); // 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(); if (null != mDownloadTask && mDownloadTask.getEntity().getUrl().equals(entity.getUrl())) {
for (DownloadTask task : taskMap.values()) { holder.refresh(mDownloadTask);
task.unRegister(createTag(task));
} }
} }
private String createTag(DownloadTask task) { // public void unRegister() {
return type + "_" + task.progress.tag; // 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 @Override
public int getItemCount() { 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; ImageView icon, remove;
TextView name, state, downloadSize; TextView name, state, downloadSize;
Button start; Button start;
NumberProgressBar pbProgress; NumberProgressBar pbProgress;
private DownloadTask task; // private DownloadTask task;
private String tag; private String tag;
Holder(@NonNull View itemView) { Holder(@NonNull View itemView) {
@@ -117,145 +167,281 @@ public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManager
pbProgress = itemView.findViewById(R.id.pbProgress); pbProgress = itemView.findViewById(R.id.pbProgress);
} }
public void setTask(DownloadTask task) {
this.task = task;
}
public void bind() { void refresh(DownloadTask task) {
switch (task.getState()) {
Progress progress = task.progress; case IEntity.STATE_OTHER:
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("下载"); start.setText("下载");
state.setText("未知");
break; break;
case Progress.PAUSE: case IEntity.STATE_FAIL:
state.setText("暂停中"); start.setText("下载");
state.setText("出错");
break;
case IEntity.STATE_COMPLETE:
start.setText("安装中");
state.setText("完成");
break;
case IEntity.STATE_STOP:
start.setText("继续"); start.setText("继续");
state.setText("停止");
break; break;
case Progress.ERROR: case IEntity.STATE_WAIT:
state.setText("下载出错");
start.setText("出错");
break;
case Progress.WAITING:
state.setText("等待中");
start.setText("等待"); start.setText("等待");
state.setText("等待");
break; break;
case Progress.FINISH: case IEntity.STATE_RUNNING:
state.setText("下载完成"); start.setText(task.getPercent() + "%");
start.setText("完成"); pbProgress.setProgress(task.getPercent());
state.setText(task.getConvertSpeed());
long progress = task.getCurrentProgress();
downloadSize.setText(FileUtils.formatFileSize(progress) + "/" + task.getConvertFileSize());
break; break;
case Progress.LOADING: case IEntity.STATE_PRE:
String speed = Formatter.formatFileSize(mContext, progress.speed); break;
state.setText(String.format("%s/s", speed)); case IEntity.STATE_POST_PRE:
start.setText("暂停"); break;
case IEntity.STATE_CANCEL:
break; break;
} }
pbProgress.setMax(10000);
pbProgress.setProgress((int) (progress.fraction * 10000));
} }
public void start() { void refreshEntity(DownloadEntity entity) {
Progress progress = task.progress; switch (entity.getState()) {
switch (progress.status) { case IEntity.STATE_OTHER:
case Progress.PAUSE: start.setText("下载");
case Progress.NONE: state.setText("未知");
case Progress.ERROR:
task.start();
break; break;
case Progress.LOADING: case IEntity.STATE_FAIL:
task.pause(); start.setText("下载");
state.setText("出错");
break; 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; break;
} }
refresh(progress);
} }
public void remove() {
task.remove(true); // public void setTask(DownloadTask task) {
updateData(type); // 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() { // private class ListDownloadListener extends DownloadListener {
task.restart(); //
} // 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) { private void ItemChanged(DownloadTask task) {
this.tag = tag; 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 { @Download.onTaskRunning
void onTaskRunning(DownloadTask task) {
private Holder holder; ItemChanged(task);
ListDownloadListener(Object tag, Holder holder) {
super(tag);
this.holder = holder;
} }
@Override @Download.onTaskComplete
public void onStart(Progress progress) { void onTaskComplete(DownloadTask task) {
ItemChanged(task);
updateNotCompleteTask();
} }
@Override @Download.onWait
public void onProgress(Progress progress) { void onWait(DownloadTask task) {
if (tag == holder.getTag()) { ItemChanged(task);
holder.refresh(progress);
}
} }
@Override @Download.onTaskStart
public void onError(Progress progress) { void onTaskStart(DownloadTask task) {
Throwable throwable = progress.exception; ItemChanged(task);
if (throwable != null) throwable.printStackTrace();
} }
@Override @Download.onPre
public void onFinish(File file, Progress progress) { void onPre(DownloadTask task) {
mhandler.sendEmptyMessage(100); ItemChanged(task);
} }
@Override @Download.onTaskResume
public void onRemove(Progress progress) { 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);
}
} }

View File

@@ -27,8 +27,6 @@ import com.bumptech.glide.Glide;
import java.util.List; import java.util.List;
import rx.Subscriber;
import rx.schedulers.Schedulers;
/** /**
* Created by asus on 2017/10/26. * 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() { holder.btnDownLoad.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
ApkUtils.uninstallApp(context, localApp.getPackageName()); ApkUtils.Uninstall(context, localApp.getPackageName());
} }
}); });
String totalLength = Formatter.formatFileSize(context, localApp.getSize()); String totalLength = Formatter.formatFileSize(context, localApp.getSize());

View File

@@ -11,19 +11,8 @@ import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.appstore.uiui.R; import com.appstore.uiui.R;
import com.appstore.uiui.bean.AppInfo;
import com.appstore.uiui.bean.UpdateAppInfo; 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; import java.util.List;
public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.UpdateAppViewHolder> { public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.UpdateAppViewHolder> {
@@ -45,14 +34,14 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
@Override @Override
public void onBindViewHolder(UpdateAppViewHolder holder, int position) { public void onBindViewHolder(UpdateAppViewHolder holder, int position) {
final UpdateAppInfo appInfo = localAppList.get(position); final UpdateAppInfo appInfo = localAppList.get(position);
final DownloadTask downloadTask = OkDownload.getInstance().getTask(appInfo.getURL()); // final DownloadTask downloadTask = OkDownload.getInstance().getTask(appInfo.getURL());
holder.setTag(appInfo.getURL()); // holder.setTag(appInfo.getURL());
if (downloadTask != null) { // if (downloadTask != null) {
downloadTask.register(new ListDownloadListener(appInfo.getURL(), holder)); // downloadTask.register(new ListDownloadListener(appInfo.getURL(), holder));
holder.setTask(downloadTask); // holder.setTask(downloadTask);
// holder.bind(); // holder.bind();
holder.refresh(downloadTask.progress); // holder.refresh(downloadTask.progress);
} // }
holder.ivIcon.setImageDrawable(appInfo.getIcon()); holder.ivIcon.setImageDrawable(appInfo.getIcon());
holder.tvName.setText(appInfo.getAppName()); holder.tvName.setText(appInfo.getAppName());
@@ -63,24 +52,24 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
holder.btnDownLoad.setOnClickListener(new View.OnClickListener() { holder.btnDownLoad.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
downloadApk(appInfo); // downloadApk(appInfo);
} }
}); });
} }
private void downloadApk(UpdateAppInfo appInfo) { // private void downloadApk(UpdateAppInfo appInfo) {
GetRequest<File> request = OkGo.get(appInfo.getURL()); // GetRequest<File> request = OkGo.get(appInfo.getURL());
//这里第一个参数是tag代表下载任务的唯一标识传任意字符串都行需要保证唯一,我这里用url作为了tag // //这里第一个参数是tag代表下载任务的唯一标识传任意字符串都行需要保证唯一,我这里用url作为了tag
OkDownload.request(appInfo.getURL(), request)// // OkDownload.request(appInfo.getURL(), request)//
// .priority(apk.priority)// //// .priority(apk.priority)//
.extra1(appInfo.getAppInfo())// // .extra1(appInfo.getAppInfo())//
.save()// // .save()//
.register(new LogDownloadListener())// // .register(new LogDownloadListener())//
.start(); // .start();
notifyDataSetChanged(); // notifyDataSetChanged();
} // }
@Override @Override
public int getItemCount() { public int getItemCount() {
@@ -98,7 +87,7 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
TextView tvUpdate; TextView tvUpdate;
Button btnDownLoad; Button btnDownLoad;
private DownloadTask task; // private DownloadTask task;
private String tag; private String tag;
public UpdateAppViewHolder(View itemView) { public UpdateAppViewHolder(View itemView) {
@@ -114,86 +103,86 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
} }
void refresh(Progress progress) { // void refresh(Progress progress) {
switch (progress.status) { // switch (progress.status) {
case Progress.NONE: // case Progress.NONE:
btnDownLoad.setText("下载"); // btnDownLoad.setText("下载");
break; // break;
case Progress.PAUSE: // case Progress.PAUSE:
btnDownLoad.setText("继续"); // btnDownLoad.setText("继续");
break; // break;
case Progress.ERROR: // case Progress.ERROR:
btnDownLoad.setText("出错"); // btnDownLoad.setText("出错");
break; // break;
case Progress.WAITING: // case Progress.WAITING:
btnDownLoad.setText("等待"); // btnDownLoad.setText("等待");
break; // break;
case Progress.FINISH: // case Progress.FINISH:
btnDownLoad.setText("完成"); // btnDownLoad.setText("完成");
//
break; // break;
case Progress.LOADING: // case Progress.LOADING:
btnDownLoad.setText((int) (progress.fraction * 100) + "%"); // btnDownLoad.setText((int) (progress.fraction * 100) + "%");
break; // break;
// }
//
// }
//
// void setTask(DownloadTask task) {
// this.task = task;
// }
//
// void setTag(String tag) {
// this.tag = tag;
// }
//
// String getTag() {
// return tag;
// }
} }
} // private class ListDownloadListener extends DownloadListener {
//
void setTask(DownloadTask task) { // private UpdateAppViewHolder holder;
this.task = task; //
} // ListDownloadListener(Object tag, UpdateAppViewHolder holder) {
// super(tag);
void setTag(String tag) { // this.holder = holder;
this.tag = tag; // }
} //
// @Override
String getTag() { // public void onStart(Progress progress) {
return tag; //
} // }
} //
// @Override
private class ListDownloadListener extends DownloadListener { // public void onProgress(Progress progress) {
// if (tag == holder.getTag()) {
private UpdateAppViewHolder holder; // holder.refresh(progress);
// }
ListDownloadListener(Object tag, UpdateAppViewHolder holder) { // }
super(tag); //
this.holder = holder; // @Override
} // public void onError(Progress progress) {
// Throwable throwable = progress.exception;
@Override // if (throwable != null) throwable.printStackTrace();
public void onStart(Progress progress) { // ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败请重试");
// }
} //
// @Override
@Override // public void onFinish(final File file, Progress progress) {
public void onProgress(Progress progress) { // ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载完成");
if (tag == holder.getTag()) { // new Thread(new Runnable() {
holder.refresh(progress); // @Override
} // public void run() {
} // ApkUtils.installApp(context,file.getAbsolutePath() );
// }
@Override // }).start();
public void onError(Progress progress) { // }
Throwable throwable = progress.exception; //
if (throwable != null) throwable.printStackTrace(); // @Override
ToastUtil.show(((AppInfo) progress.extra1).getApp_name() + "\t下载失败请重试"); // public void onRemove(Progress progress) {
} // }
// }
@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) {
}
}
} }

View 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();
}

View File

@@ -40,6 +40,7 @@ public abstract class LazyLoadFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(getLayoutId(), container, false); View view = inflater.inflate(getLayoutId(), container, false);
initViews(view); initViews(view);
initDatas();
isViewCreated = true; isViewCreated = true;
return view; return view;
} }
@@ -47,6 +48,7 @@ public abstract class LazyLoadFragment extends Fragment {
public abstract int getLayoutId(); public abstract int getLayoutId();
public abstract void initViews(View view); public abstract void initViews(View view);
public abstract void initDatas();
@Override @Override
public void setUserVisibleHint(boolean isVisibleToUser) { public void setUserVisibleHint(boolean isVisibleToUser) {

View File

@@ -7,8 +7,8 @@ public class AppInfo implements Serializable {
private String app_name; private String app_name;
private String app_package; private String app_package;
private String app_version_name; private String app_version_name;
private String app_version_code; private int app_version_code;
private String app_size; private long app_size;
private String app_desc; private String app_desc;
private String app_url; private String app_url;
private String app_img; private String app_img;
@@ -25,12 +25,9 @@ public class AppInfo implements Serializable {
private int is_delete; private int is_delete;
private int is_update; private int is_update;
private int is_silent; private int is_silent;
private String app_md5;
private String createtime; private String createtime;
private boolean isInstall = false;
private boolean isUpdate = false;
public int getApp_id() { public int getApp_id() {
return app_id; return app_id;
} }
@@ -63,19 +60,19 @@ public class AppInfo implements Serializable {
this.app_version_name = app_version_name; this.app_version_name = app_version_name;
} }
public String getApp_version_code() { public int getApp_version_code() {
return app_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; this.app_version_code = app_version_code;
} }
public String getApp_size() { public long getApp_size() {
return app_size; return app_size;
} }
public void setApp_size(String app_size) { public void setApp_size(long app_size) {
this.app_size = app_size; this.app_size = app_size;
} }
@@ -215,19 +212,11 @@ public class AppInfo implements Serializable {
this.createtime = createtime; this.createtime = createtime;
} }
public void setInstall(boolean b) { public String getApp_md5() {
this.isInstall = b; return app_md5;
} }
public boolean isInstall() { public void setApp_md5(String app_md5) {
return isInstall; this.app_md5 = app_md5;
}
public boolean isUpdate() {
return isUpdate;
}
public void setUpdate(boolean b) {
this.isUpdate = b;
} }
} }

View File

@@ -1,9 +1,25 @@
package com.appstore.uiui.bean; package com.appstore.uiui.bean;
import androidx.annotation.NonNull;
import java.io.Serializable; 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 int code;
public String data;
public String msg; public String msg;
public T data;
@NonNull
@Override
public String toString() {
return "{\n" +//
"\tcode=" + code + "\n" +//
"\tmsg='" + msg + "\'\n" +//
"\tdata=" + data + "\n" +//
'}';
}
} }

View 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;
}
}

View File

@@ -1,27 +1,30 @@
package com.appstore.uiui.base; package com.appstore.uiui.bean;
import java.io.Serializable; import java.io.Serializable;
public class UserInfo implements 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_value;
private String sn_name; private String sn_name;
private String sn_phone; private String sn_phone;
private String sn_school; private String grade;
private int sn_grade;
private String sn_app; private String sn_app;
private String sn_area; private String sn_area;
private int member_id; private int admin_id;
private int is_delete; private String is_delete;
private int is_reset; private String is_reset;
private int is_lock; private String is_lock;
private String school;
private String createtime; private String createtime;
public String getId() { public int getId() {
return id; return id;
} }
public void setId(String id) { public void setId(int id) {
this.id = id; this.id = id;
} }
@@ -49,20 +52,12 @@ public class UserInfo implements Serializable {
this.sn_phone = sn_phone; this.sn_phone = sn_phone;
} }
public String getSn_school() { public String getGrade() {
return sn_school; return grade;
} }
public void setSn_school(String sn_school) { public void setGrade(String grade) {
this.sn_school = sn_school; this.grade = grade;
}
public int getSn_grade() {
return sn_grade;
}
public void setSn_grade(int sn_grade) {
this.sn_grade = sn_grade;
} }
public String getSn_app() { public String getSn_app() {
@@ -81,35 +76,35 @@ public class UserInfo implements Serializable {
this.sn_area = sn_area; this.sn_area = sn_area;
} }
public int getMember_id() { public int getAdmin_id() {
return member_id; return admin_id;
} }
public void setMember_id(int member_id) { public void setAdmin_id(int admin_id) {
this.member_id = member_id; this.admin_id = admin_id;
} }
public int getIs_delete() { public String getIs_delete() {
return is_delete; return is_delete;
} }
public void setIs_delete(int is_delete) { public void setIs_delete(String is_delete) {
this.is_delete = is_delete; this.is_delete = is_delete;
} }
public int getIs_reset() { public String getIs_reset() {
return is_reset; return is_reset;
} }
public void setIs_reset(int is_reset) { public void setIs_reset(String is_reset) {
this.is_reset = is_reset; this.is_reset = is_reset;
} }
public int getIs_lock() { public String getIs_lock() {
return is_lock; return is_lock;
} }
public void setIs_lock(int is_lock) { public void setIs_lock(String is_lock) {
this.is_lock = is_lock; this.is_lock = is_lock;
} }
@@ -120,4 +115,12 @@ public class UserInfo implements Serializable {
public void setCreatetime(String createtime) { public void setCreatetime(String createtime) {
this.createtime = createtime; this.createtime = createtime;
} }
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
} }

View File

@@ -8,12 +8,14 @@ import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;
import com.appstore.uiui.R; import com.appstore.uiui.R;
import com.appstore.uiui.adapter.AppAdapter; 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.base.RefreshManager;
import com.appstore.uiui.bean.AppInfo; import com.appstore.uiui.bean.AppInfo;
import com.appstore.uiui.bean.AppInfos; 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.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.ApkUtils;
import com.appstore.uiui.utils.LogUtils; 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.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout; import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener; import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
@@ -39,6 +46,12 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; 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. * Created by asus on 2017/10/23.
@@ -58,6 +71,7 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
private installReceiver myReceiver; private installReceiver myReceiver;
private Context mContext; private Context mContext;
private String TAG = "FeaturedFragment";
public FeaturedFragment() { public FeaturedFragment() {
@@ -71,9 +85,15 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
@Override @Override
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
if (myReceiver != null) { if (myReceiver != null) {
try { try {
mContext.unregisterReceiver(myReceiver); getActivity().unregisterReceiver(myReceiver);
} catch (Exception e) { } catch (Exception e) {
LogUtils.e("onStop", e.getMessage()); LogUtils.e("onStop", e.getMessage());
} }
@@ -81,10 +101,9 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
} }
@Override @Override
public void onStart() { public void initDatas() {
super.onStart();
mContext = this.getActivity(); mContext = this.getActivity();
adapter = new AppAdapter(newAppInfoList, false, getContext()); adapter = new AppAdapter(newAppInfoList, getActivity());
adapter.setHasStableIds(true); adapter.setHasStableIds(true);
int orientation = 0; int orientation = 0;
orientation = mContext.getResources().getConfiguration().orientation; orientation = mContext.getResources().getConfiguration().orientation;
@@ -109,30 +128,39 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
}); });
mRefreshLayout.autoRefresh(); mRefreshLayout.autoRefresh();
adapter.setData(checkUpdateOrInstalled(newAppInfoList)); adapter.setData(newAppInfoList);
adapter.notifyDataSetChanged(); 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 @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
adapter.notifyDataSetChanged(); 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 @Override
public void initViews(View view) { public void initViews(View view) {
mRvResult = view.findViewById(R.id.featured_rv_result); mRvResult = view.findViewById(R.id.featured_rv_result);
((SimpleItemAnimator) mRvResult.getItemAnimator()).setSupportsChangeAnimations(false);
// mRvResult.setItemAnimator(null);
imageView = view.findViewById(R.id.imageView); imageView = view.findViewById(R.id.imageView);
mRefreshLayout = view.findViewById(R.id.featured_refresh_layout); mRefreshLayout = view.findViewById(R.id.featured_refresh_layout);
RefreshManager.getInstance().register(this); RefreshManager.getInstance().register(this);
@@ -149,14 +177,13 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
.setOnPageClickListener(new BannerViewPager.OnPageClickListener() { .setOnPageClickListener(new BannerViewPager.OnPageClickListener() {
@Override @Override
public void onPageClick(int position) { public void onPageClick(int position) {
ToastUtils.showShort("position:" + position);
} }
}) })
.setInterval(5000); .setInterval(5000);
isNotLoadBitmap = false; isNotLoadBitmap = false;
} }
@Override @Override
@@ -166,8 +193,10 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
} }
synchronized private void initAPPData(final Handler handler) { synchronized private void initAPPData(final Handler handler) {
OKGO.getAllAppInfo(handler); // OKGO.getAllAppInfo(handler);
OKGO.getBannerImg(handler); getAllAppInfo();
// OKGO.getBannerImg(handler);
getBannerImg();
} }
@@ -178,7 +207,102 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
@Override @Override
public void onLoadBitMap(boolean isLoad) { 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() { Handler handler = new Handler() {
@@ -186,17 +310,17 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
super.handleMessage(msg); super.handleMessage(msg);
switch (msg.what) { switch (msg.what) {
case 0: // case 0:
mRvResult.setVisibility(View.GONE); // mRvResult.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE); // imageView.setVisibility(View.VISIBLE);
break; // break;
case 1: // case 1:
mRvResult.setVisibility(View.VISIBLE); // mRvResult.setVisibility(View.VISIBLE);
imageView.setVisibility(View.GONE); // imageView.setVisibility(View.GONE);
newAppInfoList = (List<AppInfo>) msg.obj; // newAppInfoList = (List<AppInfo>) msg.obj;
adapter.setData(checkUpdateOrInstalled(newAppInfoList)); // adapter.setData(checkUpdateOrInstalled(newAppInfoList));
adapter.notifyDataSetChanged(); // adapter.notifyDataSetChanged();
break; // break;
case 200: case 200:
List<String> list = (List<String>) msg.obj; List<String> list = (List<String>) msg.obj;
mViewPager mViewPager
@@ -213,7 +337,7 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
.setOnPageClickListener(new BannerViewPager.OnPageClickListener() { .setOnPageClickListener(new BannerViewPager.OnPageClickListener() {
@Override @Override
public void onPageClick(int position) { public void onPageClick(int position) {
ToastUtils.showShort("position:" + position);
} }
}) })
.setInterval(5000) .setInterval(5000)
@@ -224,22 +348,25 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
} }
}; };
public List<AppInfo> checkUpdateOrInstalled(List<AppInfo> list) { // public List<AppInfo> checkUpdateOrInstalled(List<AppInfo> list) {
for (AppInfo appInfo : list) { // for (AppInfo appInfo : list) {
appInfo.setInstall(ApkUtils.isAvailable(mContext, appInfo.getApp_package())); // appInfo.setInstall(ApkUtils.isAvailable(mContext, appInfo.getApp_package()));
appInfo.setUpdate(ApkUtils.checkIsUpdate(mContext, appInfo.getApp_package(), Integer.parseInt(appInfo.getApp_version_code()))); // appInfo.setUpdate(ApkUtils.checkIsUpdate(mContext, appInfo.getApp_package(), Integer.parseInt(appInfo.getApp_version_code())));
} // }
return list; // return list;
} // }
public class installReceiver extends BroadcastReceiver { public class installReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); 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")) { if (action.equals(Intent.ACTION_PACKAGE_ADDED)
adapter.setData(checkUpdateOrInstalled(newAppInfoList)); || action.equals(Intent.ACTION_PACKAGE_REPLACED)
|| action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
// adapter.setData(checkUpdateOrInstalled(newAppInfoList));
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
Log.e("installReceiver", action);
} }
} }

View File

@@ -20,7 +20,6 @@ import com.appstore.uiui.base.BaseFragment;
import com.appstore.uiui.base.RefreshManager; import com.appstore.uiui.base.RefreshManager;
import com.appstore.uiui.bean.Kind; import com.appstore.uiui.bean.Kind;
import com.appstore.uiui.network.OKGO; import com.appstore.uiui.network.OKGO;
import com.lzy.okgo.OkGo;
import com.scwang.smartrefresh.layout.SmartRefreshLayout; import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout; import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener; import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
@@ -80,7 +79,7 @@ public class KindFragment extends BaseFragment implements RefreshManager.Refresh
} }
private void initData() { private void initData() {
OKGO.getSubClassfy(mHandler); // OKGO.getSubClassfy(mHandler);
} }
private Handler mHandler = new Handler() { private Handler mHandler = new Handler() {

View File

@@ -85,6 +85,11 @@ public class ManageFragment extends LazyLoadFragment {
} }
@Override
public void initDatas() {
}
@Override @Override
public void loadData(Bundle savedInstanceState) { public void loadData(Bundle savedInstanceState) {
@@ -98,7 +103,7 @@ public class ManageFragment extends LazyLoadFragment {
} }
synchronized private void initAPPData(final Handler handler) { synchronized private void initAPPData(final Handler handler) {
OKGO.getAllAppInfo(handler); // OKGO.getAllAppInfo(handler);
} }
synchronized private List<LocalApp> getLocalApp() { synchronized private List<LocalApp> getLocalApp() {
@@ -147,13 +152,13 @@ public class ManageFragment extends LazyLoadFragment {
for (LocalApp app : localAppList) { for (LocalApp app : localAppList) {
if (packageNameList.contains(app.getPackageName())) { if (packageNameList.contains(app.getPackageName())) {
AppInfo info = list.get(packageNameList.indexOf(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 updateAppInfo = new UpdateAppInfo();
updateAppInfo.setVersionCode(app.getVersionCode()); updateAppInfo.setVersionCode(app.getVersionCode());
updateAppInfo.setVersionName(app.getVersion()); updateAppInfo.setVersionName(app.getVersion());
updateAppInfo.setAppName(app.getAppName()); updateAppInfo.setAppName(app.getAppName());
updateAppInfo.setIcon(app.getIcon()); 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.setNewVersionName(info.getApp_version_name());
updateAppInfo.setURL(info.getApp_url()); updateAppInfo.setURL(info.getApp_url());
updateAppInfo.setPackageName(info.getApp_package()); updateAppInfo.setPackageName(info.getApp_package());

View File

@@ -51,6 +51,11 @@ public class RankFragment extends LazyLoadFragment implements RefreshManager.Ref
initView(); initView();
} }
@Override
public void initDatas() {
}
@Override @Override
public void loadData(Bundle savedInstanceState) { public void loadData(Bundle savedInstanceState) {
@@ -59,7 +64,7 @@ public class RankFragment extends LazyLoadFragment implements RefreshManager.Ref
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
OKGO.getRankApp(handler); // OKGO.getRankApp(handler);
LogUtils.e("fht", "RankFragment onStart"); LogUtils.e("fht", "RankFragment onStart");
} }
@@ -93,7 +98,7 @@ public class RankFragment extends LazyLoadFragment implements RefreshManager.Ref
private void initView() { private void initView() {
mAppInfoList = new ArrayList<>(); mAppInfoList = new ArrayList<>();
mAppAdapter = new AppAdapter(mAppInfoList, true, getContext()); mAppAdapter = new AppAdapter(mAppInfoList, getActivity());
mRvResult.setLayoutManager(new LinearLayoutManager(getActivity())); mRvResult.setLayoutManager(new LinearLayoutManager(getActivity()));
mRvResult.setAdapter(mAppAdapter); mRvResult.setAdapter(mAppAdapter);
mRefreshLayout.setEnableRefresh(true); mRefreshLayout.setEnableRefresh(true);
@@ -101,7 +106,7 @@ public class RankFragment extends LazyLoadFragment implements RefreshManager.Ref
mRefreshLayout.setOnRefreshListener(new OnRefreshListener() { mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override @Override
public void onRefresh(RefreshLayout refreshlayout) { 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) { switch (msg.what) {
case 1: case 1:
mAppInfoList = (List<AppInfo>) msg.obj; mAppInfoList = (List<AppInfo>) msg.obj;
mAppAdapter.setData(checkUpdateOrInstalled(mAppInfoList)); mAppAdapter.setData(mAppInfoList);
mAppAdapter.notifyDataSetChanged(); mAppAdapter.notifyDataSetChanged();
break; 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;
}
} }

View File

@@ -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);
}
}

View 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;
}
}

View File

@@ -10,24 +10,23 @@ import androidx.annotation.NonNull;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.appstore.uiui.TextCode.MessageWhat; import com.appstore.uiui.TextCode.MessageWhat;
import com.appstore.uiui.base.UserInfo;
import com.appstore.uiui.bean.AppInfo; import com.appstore.uiui.bean.AppInfo;
import com.appstore.uiui.bean.BaseResponse;
import com.appstore.uiui.bean.bannerImage; 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.LogUtils;
import com.appstore.uiui.utils.SPUtils; import com.appstore.uiui.utils.SPUtils;
import com.appstore.uiui.utils.ToastUtil; import com.appstore.uiui.utils.ToastUtil;
import com.appstore.uiui.utils.Utils; 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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 { public class OKGO {
@@ -35,480 +34,480 @@ public class OKGO {
private static final int GET_USERINFO = 1; private static final int GET_USERINFO = 1;
private static final int GET_SORTAPP = 2; private static final int GET_SORTAPP = 2;
private Handler mhandler = new Handler() { // private Handler mhandler = new Handler() {
@Override // @Override
public void handleMessage(@NonNull Message msg) { // public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg); // super.handleMessage(msg);
switch (msg.what) { // switch (msg.what) {
case GET_ALL_APPINFO: // case GET_ALL_APPINFO:
break; // break;
case GET_USERINFO: // case GET_USERINFO:
//
// break;
// case GET_SORTAPP:
//
// break;
// }
// }
// };
break; // synchronized public static void getAllAppInfo(final Handler handler) {
case GET_SORTAPP: // OkGo.<String>post(UrlAddress.GET_ALL_APPINFO)
// .params("sn", Utils.getSerial())
break; // .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) { //// LogUtils.e("onSuccess", body.toString());
OkGo.<String>post(Url.GET_ALL_APPINFO) // LogUtils.e("fht", "getAllAppInfo onSuccess");
.params("sn", Utils.getSerial()) // int code = body.getInteger("code");
.execute(new StringCallback() { // String msg = body.getString("msg");
@Override // String data = body.getString("data");
public void onSuccess(Response<String> response) { // List<AppInfo> applist = JSON.parseArray(data, AppInfo.class);
try { // if (code == MessageWhat.CODE_SUCCESSFUL) {
JSONObject body = JSON.parseObject(response.body()); // 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("onSuccess", body.toString());
LogUtils.e("fht", "getAllAppInfo onSuccess"); // LogUtils.e("fht", "searchAppbyName onSuccess");
int code = body.getInteger("code"); // int code = body.getInteger("code");
String msg = body.getString("msg"); // String msg = body.getString("msg");
String data = body.getString("data"); // String data = body.getString("data");
List<AppInfo> applist = JSON.parseArray(data, AppInfo.class); // List<AppInfo> applist = JSON.parseArray(data, AppInfo.class);
if (code == MessageWhat.CODE_SUCCESSFUL) { // if (code == MessageWhat.CODE_SUCCESSFUL) {
Message message = new Message(); // Message message = new Message();
message.what = 1; // message.what = 1;
message.obj = applist; // message.obj = applist;
handler.sendMessage(message); // handler.sendMessage(message);
} else { // } else {
ToastUtil.show(msg); // ToastUtil.show(msg);
handler.sendEmptyMessage(0); // handler.sendEmptyMessage(0);
} // }
} catch (Exception e) { // } catch (Exception e) {
LogUtils.e("Exception", e.getMessage()); // LogUtils.e("Exception", e.getMessage());
ToastUtil.show("服务器错误,请稍后重试"); // ToastUtil.show("服务器错误,请稍后重试");
handler.sendEmptyMessage(0); // handler.sendEmptyMessage(0);
} // }
} // }
//
@Override // @Override
public void onError(Response<String> response) { // public void onError(Response<String> response) {
super.onError(response); // super.onError(response);
LogUtils.e("getAllAppInfo", response.getException().toString()); // LogUtils.e("searchAppbyName", response.getException().toString());
ToastUtil.show("网络连接失败,检查网络连接"); // ToastUtil.show("网络连接失败,检查网络连接");
handler.sendEmptyMessage(0); // handler.sendEmptyMessage(0);
} //
}); // }
} // });
public static synchronized void checkDevicesInfo(final Context context) { // }
OkGo.<String>post(Url.GET_INFO_FROMESN) //
.params("sn", Utils.getSerial()) // synchronized public static void getUserInfo(final Handler handler) {
.execute(new StringCallback() { // String sn = Utils.getSerial();
@Override // OkGo.<String>get(UrlAddress.GET_INFO_FROMESN)
public void onSuccess(Response<String> response) { // .params("sn", sn)
Log.e("onSuccess", "checkDevicesInfo"); // .execute(new StringCallback() {
try { // @Override
JSONObject bodyObject = JSON.parseObject(response.body()); // public void onSuccess(Response<String> response) {
Integer code = (bodyObject.getInteger("code")); // LogUtils.e("fht", "getUserInfo onSuccess");
String msg = bodyObject.getString("msg"); // JSONObject jsonObject = JSON.parseObject(response.body());
String data = bodyObject.getString("data"); // int code = jsonObject.getInteger("code");
UserInfo userInfo = JSON.parseObject(data, UserInfo.class); // String msg = jsonObject.getString("msg");
if (code == 200) { // if (code == MessageWhat.CODE_SUCCESSFUL) {
SPUtils.put(context, "isLogined", 1); // String data = jsonObject.getString("data");
SPUtils.put(context, "member_id", userInfo.getMember_id()); // SNInfo userInfo = JSON.parseObject(data, SNInfo.class);
SPUtils.put(context, "sn_id", userInfo.getId()); // Message message = new Message();
} else if (code == -200) { // message.what = 1;
SPUtils.put(context, "isLogined", 0); // message.obj = userInfo;
// handler.sendMessage(message);
} else if (code == -250) { // } else {
SPUtils.put(context, "isLogined", 2); // ToastUtil.show(msg);
//设备验证 // }
} // }
} catch (Exception ex) { //
Log.e("checkDevicesInfo", ex.getMessage()); // @Override
} // public void onError(Response<String> response) {
} // super.onError(response);
// LogUtils.e("getUserInfo", response.getException().toString());
@Override // ToastUtil.show("网络连接失败,检查网络连接");
public void onError(Response<String> response) { // }
super.onError(response); // });
Log.e("onError", response.getException().toString()); // }
//
} // synchronized public static void getUserInfo(final Context context) {
}); // OkGo.<String>get(UrlAddress.GET_INFO_FROMESN)
} // .params("sn", Utils.getSerial())
// .execute(new StringCallback() {
synchronized public static void getAllAppPackageName(final Handler handler) { // @Override
OkGo.<String>post(Url.GET_ALL_PACKAGENAME) // public void onSuccess(Response<String> response) {
.params("sn", Utils.getSerial()) // LogUtils.e("fht", "getUserInfo onSuccess");
.execute(new StringCallback() { // JSONObject jsonObject = JSON.parseObject(response.body());
@Override // int code = jsonObject.getInteger("code");
public void onSuccess(Response<String> response) { // String msg = jsonObject.getString("msg");
String s = response.body(); // if (code == MessageWhat.CODE_SUCCESSFUL) {
try { // String data = jsonObject.getString("data");
JSONObject body = JSON.parseObject(s); // SNInfo userInfo = JSON.parseObject(data, SNInfo.class);
int code = body.getInteger("code"); // SPUtils.put(context, "member_id", userInfo.getMember_id());
String msg = body.getString("msg"); // SPUtils.put(context, "sn_id", userInfo.getId());
String data = body.getString("data"); // SPUtils.put(context, "sn_grade", userInfo.getSn_grade());
if (code == 200) { // } else {
List<JSONObject> jsonArray = JSON.parseArray(data, JSONObject.class); // ToastUtil.show(msg);
String packageList = ""; // }
for (JSONObject jsonObject : jsonArray) { // }
packageList += jsonObject.getString("app_package") + ","; //
} // @Override
if (!packageList.isEmpty()) { // public void onError(Response<String> response) {
Log.e("fht", packageList); // super.onError(response);
Message message = new Message(); // LogUtils.e("getUserInfo", response.getException().toString());
message.what = 201; // ToastUtil.show("网络连接失败,检查网络连接");
message.obj = packageList; // }
handler.sendMessage(message); // });
} else { // }
handler.sendEmptyMessage(202); //
} // synchronized public static void getSortApp(final Handler handler, int type, int grade, int subject) {
} // OkGo.<String>post(UrlAddress.GET_SORT_APP)
} catch (Exception e) { // .params("sn", Utils.getSerial())
// .params("app_type", type)//应用分类 0学习 1娱乐
} // .params("grade", grade)//年级 以数字代表
} // .params("subject", subject) //科目 以数字代表
// .execute(new StringCallback() {
@Override // @Override
public void onError(Response<String> response) { // public void onSuccess(Response<String> response) {
super.onError(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");
synchronized public static void getRankApp(final Handler handler) { // if (code == MessageWhat.CODE_SUCCESSFUL) {
OkGo.<String>get(Url.GET_ALL_RANK).execute(new StringCallback() { // String data = jsonObject.getString("data");
@Override // List<AppInfo> list = JSON.parseArray(data, AppInfo.class);
public void onSuccess(Response<String> response) { // Message message = new Message();
try { // message.what = 1;
JSONObject body = JSON.parseObject(response.body()); // message.obj = list;
// LogUtils.e("onSuccess", body.toString()); // handler.sendMessage(message);
LogUtils.e("fht", "getAllAppInfo onSuccess"); // } else {
int code = body.getInteger("code"); // ToastUtil.show(msg);
String msg = body.getString("msg"); // handler.sendEmptyMessage(0);
String data = body.getString("data"); // }
List<AppInfo> applist = JSON.parseArray(data, AppInfo.class); // }
if (code == MessageWhat.CODE_SUCCESSFUL) { //
Message message = new Message(); // @Override
message.what = 1; // public void onError(Response<String> response) {
message.obj = applist; // super.onError(response);
handler.sendMessage(message); // LogUtils.e("getSortApp", response.getException().toString());
} else { // ToastUtil.show("网络连接失败,检查网络连接");
ToastUtil.show(msg); // handler.sendEmptyMessage(0);
handler.sendEmptyMessage(0); // }
} // });
} catch (Exception e) { // }
LogUtils.e("Exception", e.getMessage()); //
ToastUtil.show("服务器错误,请稍后重试"); // synchronized public static void setAppinstallInfo(int member_id, String sn_id, String app_name, String packageName) {
handler.sendEmptyMessage(0); // OkGo.<String>post(UrlAddress.SET_APP_INSTALL_INFO)
} // .params("member_id", member_id)
} // .params("sn_id", sn_id)
// .params("app_name", app_name)
@Override // .params("package", packageName)
public void onError(Response<String> response) { // .execute(new StringCallback() {
super.onError(response); // @Override
LogUtils.e("getRankApp", response.getException().toString()); // public void onSuccess(Response<String> response) {
ToastUtil.show("网络连接失败,检查网络连接"); // JSONObject object = JSON.parseObject(response.body());
handler.sendEmptyMessage(0); // int code = object.getInteger("code");
} // String msg = object.getString("msg");
}); // LogUtils.e("setAppinstallInfo", msg);
} // }
//
synchronized public static void searchAppbyName(final Handler handler, String app_name) { // @Override
OkGo.<String>post(Url.GET_APPSEARCHE) // public void onError(Response<String> response) {
.params("sn", Utils.getSerial()) // super.onError(response);
.params("app_name", app_name) // LogUtils.e("setAppinstallInfo", "onError:" + response.getException());
.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"); // synchronized public static void setAppuninstallInfo(String sn_id, String packageName) {
int code = body.getInteger("code"); // OkGo.<String>post(UrlAddress.SET_APP_UNINSTALL_INFO)
String msg = body.getString("msg"); // .params("sn_id", sn_id)
String data = body.getString("data"); // .params("package", packageName)
List<AppInfo> applist = JSON.parseArray(data, AppInfo.class); // .execute(new StringCallback() {
if (code == MessageWhat.CODE_SUCCESSFUL) { // @Override
Message message = new Message(); // public void onSuccess(Response<String> response) {
message.what = 1; // JSONObject object = JSON.parseObject(response.body());
message.obj = applist; // int code = object.getInteger("code");
handler.sendMessage(message); // String msg = object.getString("msg");
} else { // LogUtils.e("setAppinstallInfo", msg);
ToastUtil.show(msg); // if (code == MessageWhat.CODE_SUCCESSFUL) {
handler.sendEmptyMessage(0); //
} // } else {
} catch (Exception e) { //
LogUtils.e("Exception", e.getMessage()); // }
ToastUtil.show("服务器错误,请稍后重试"); // }
handler.sendEmptyMessage(0); //
} // @Override
} // public void onError(Response<String> response) {
// super.onError(response);
@Override // LogUtils.e("setAppinstallInfo", "onError:" + response.getException());
public void onError(Response<String> response) { //
super.onError(response); // }
LogUtils.e("searchAppbyName", response.getException().toString()); // });
ToastUtil.show("网络连接失败,检查网络连接"); //
handler.sendEmptyMessage(0); // }
//
} // 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() {
synchronized public static void getUserInfo(final Handler handler) { // @Override
String sn = Utils.getSerial(); // public void onSuccess(Response<String> response) {
OkGo.<String>post(Url.GET_INFO_FROMESN) // try {
.params("sn", sn) // JSONObject body = JSON.parseObject(response.body());
.execute(new StringCallback() { // int code = body.getInteger("code");
@Override // String msg = body.getString("msg");
public void onSuccess(Response<String> response) { // if (code == 200) {
LogUtils.e("fht", "getUserInfo onSuccess"); // Message message = new Message();
JSONObject jsonObject = JSON.parseObject(response.body()); // JSONObject data = JSON.parseObject(body.getString("data"));
int code = jsonObject.getInteger("code"); // if (data != null) {
String msg = jsonObject.getString("msg"); // String url = data.getString("downloadurl");
if (code == MessageWhat.CODE_SUCCESSFUL) { // message.what = 200;
String data = jsonObject.getString("data"); // message.obj = url;
UserInfo userInfo = JSON.parseObject(data, UserInfo.class); // } else {
Message message = new Message(); // message.what = -200;
message.what = 1; // }
message.obj = userInfo; // handler.sendMessage(message);
handler.sendMessage(message); // } else {
} else { // Log.e("checkUpdateByPackage", packageName + msg);
ToastUtil.show(msg); // }
} // } catch (Exception e) {
} // Log.e("checkUpdateByPackage", e.getMessage());
// }
@Override // }
public void onError(Response<String> response) { //
super.onError(response); // @Override
LogUtils.e("getUserInfo", response.getException().toString()); // public void onError(Response<String> response) {
ToastUtil.show("网络连接失败,检查网络连接"); // super.onError(response);
} // Log.e("checkUpdateByPackage", response.getException().toString());
}); // }
} // });
// }
synchronized public static void getUserInfo(final Context context) { //
OkGo.<String>post(Url.GET_INFO_FROMESN) // public static void getBannerImg(final Handler handler) {
.params("sn", Utils.getSerial()) // OkGo.<String>get(UrlAddress.GET_BANNER_IMG).execute(new StringCallback() {
.execute(new StringCallback() { // @Override
@Override // public void onSuccess(Response<String> response) {
public void onSuccess(Response<String> response) { // try {
LogUtils.e("fht", "getUserInfo onSuccess"); // JSONObject body = JSON.parseObject(response.body());
JSONObject jsonObject = JSON.parseObject(response.body()); // int code = body.getInteger("code");
int code = jsonObject.getInteger("code"); // String msg = body.getString("msg");
String msg = jsonObject.getString("msg"); // if (code == 200) {
if (code == MessageWhat.CODE_SUCCESSFUL) { // Message message = new Message();
String data = jsonObject.getString("data"); // List<bannerImage> data = JSON.parseArray(body.getString("data"), bannerImage.class);
UserInfo userInfo = JSON.parseObject(data, UserInfo.class); // if (data != null) {
SPUtils.put(context, "member_id", userInfo.getMember_id()); // List<String> urlList = new ArrayList<>();
SPUtils.put(context, "sn_id", userInfo.getId()); // for (int i = 0; i < data.size(); i++) {
SPUtils.put(context, "sn_grade", userInfo.getSn_grade()); // urlList.add(data.get(0).getImg());
} else { // }
ToastUtil.show(msg); // message.what = 200;
} // message.obj = urlList;
} // } else {
// message.what = -200;
@Override // }
public void onError(Response<String> response) { // handler.sendMessage(message);
super.onError(response); // } else {
LogUtils.e("getUserInfo", response.getException().toString()); // Log.e("checkUpdateByPackage", msg);
ToastUtil.show("网络连接失败,检查网络连接"); // }
} // } catch (Exception e) {
}); // Log.e("checkUpdateByPackage", e.getMessage());
} // }
// }
synchronized public static void getSortApp(final Handler handler, int type, int grade, int subject) { //
OkGo.<String>post(Url.GET_SORT_APP) // @Override
.params("sn", Utils.getSerial()) // public void onError(Response<String> response) {
.params("app_type", type)//应用分类 0学习 1娱乐 // super.onError(response);
.params("grade", grade)//年级 以数字代表 // }
.params("subject", subject) //科目 以数字代表 // });
.execute(new StringCallback() { //
@Override // }
public void onSuccess(Response<String> response) { //
LogUtils.e("fht", "getSortApp onSuccess"); // public static void getSubClassfy(final Handler handler) {
JSONObject jsonObject = JSON.parseObject(response.body()); // OkGo.<String>post(UrlAddress.GET_SUBClASSFY)
LogUtils.e("fht", jsonObject.toString()); // .params("sn", Utils.getSerial())
int code = jsonObject.getInteger("code"); // .execute(new StringCallback() {
String msg = jsonObject.getString("msg"); // @Override
if (code == MessageWhat.CODE_SUCCESSFUL) { // public void onSuccess(Response<String> response) {
String data = jsonObject.getString("data"); // JSONObject jsonObject = JSONObject.parseObject(response.body());
List<AppInfo> list = JSON.parseArray(data, AppInfo.class); // int code = jsonObject.getInteger("code");
Message message = new Message(); // String msg = jsonObject.getString("msg");
message.what = 1; // if (code == 200) {
message.obj = list; // String data = jsonObject.getString("data");
handler.sendMessage(message); // if (!data.equals("")) {
} else { // List<String> list = Arrays.asList(data.split(","));
ToastUtil.show(msg); // Message message = new Message();
handler.sendEmptyMessage(0); // message.what = 200;
} // message.obj = list;
} // handler.sendMessage(message);
// }
@Override // } else {
public void onError(Response<String> response) { // ToastUtil.debugShow(msg);
super.onError(response); // handler.sendEmptyMessage(-200);
LogUtils.e("getSortApp", response.getException().toString()); // }
ToastUtil.show("网络连接失败,检查网络连接"); //
handler.sendEmptyMessage(0); // }
} //
}); // @Override
} // public void onError(Response<String> response) {
// super.onError(response);
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);
}
});
}
} }

View File

@@ -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";
//获取应用分类
}

View File

@@ -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";
}

View File

@@ -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
);
}

View File

@@ -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
);
}

View File

@@ -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
);
}

View 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
);
}

View File

@@ -20,8 +20,8 @@ public class AppManagerReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
int member_id = (int) SPUtils.get(context, "member_id", -1); int admin_id = (int) SPUtils.get(context, "admin_id", -1);
String sn_id = (String) SPUtils.get(context, "sn_id", "-1"); int sn_id = (int) SPUtils.get(context, "sn_id", -1);
Log.e("BootReceiver", intent.getAction()); Log.e("BootReceiver", intent.getAction());
action = intent.getAction(); action = intent.getAction();
@@ -42,10 +42,10 @@ public class AppManagerReceiver extends BroadcastReceiver {
LogUtils.e(TAG, "安装了:" + packageName + "包名的程序"); LogUtils.e(TAG, "安装了:" + packageName + "包名的程序");
// ToastTool.show("安装成功"); // ToastTool.show("安装成功");
if (!packageName.equals(context.getPackageName()) && !Arrays.asList(packages).contains(packageName)) { if (!packageName.equals(context.getPackageName()) && !Arrays.asList(packages).contains(packageName)) {
if (member_id == -1 || sn_id.equals("-1")) { if (admin_id == -1 || sn_id == -1) {
OKGO.getUserInfo(context); // OKGO.getUserInfo(context);
} else { } 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 + "包名的程序"); LogUtils.e(TAG, "卸载了:" + packageName + "包名的程序");
Intent intents = new Intent("com.appstore.uiui.PACKAGE_REMOVED"); Intent intents = new Intent("com.appstore.uiui.PACKAGE_REMOVED");
context.sendBroadcast(intents); context.sendBroadcast(intents);
if (!packageName.equals(context.getPackageName())&& !Arrays.asList(packages).contains(packageName)) { if (!packageName.equals(context.getPackageName()) && !Arrays.asList(packages).contains(packageName)) {
if (member_id == -1 || sn_id.equals("-1")) { if (admin_id == -1 || sn_id == -1) {
OKGO.getUserInfo(context); // OKGO.getUserInfo(context);
} else { } else {
OKGO.setAppuninstallInfo(sn_id, packageName); // OKGO.setAppuninstallInfo(sn_id, packageName);
} }
} }
} }
@@ -70,6 +70,7 @@ public class AppManagerReceiver extends BroadcastReceiver {
} }
String[] packages = { String[] packages = {
"com.appstore.uiui", "com.appstore.uiui",
"com.uiuios.updatetools", "com.uiuios.updatetools",

View File

@@ -17,7 +17,7 @@ public class BootReceiver extends BroadcastReceiver {
context.startService(new Intent(context, InitJpushServer.class)); context.startService(new Intent(context, InitJpushServer.class));
context.startService(new Intent(context, StepService.class)); context.startService(new Intent(context, StepService.class));
context.startService(new Intent(context, GuardService.class)); context.startService(new Intent(context, GuardService.class));
OKGO.getUserInfo(context); // OKGO.getUserInfo(context);
LogUtils.e("fht", "booting BootReceiver"); LogUtils.e("fht", "booting BootReceiver");
} }
} }

View File

@@ -23,22 +23,28 @@ import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.appstore.uiui.KeepAliveConnection; 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.ApkUtils;
import com.appstore.uiui.utils.LogUtils; import com.appstore.uiui.utils.LogUtils;
import com.appstore.uiui.utils.SPUtils;
import com.appstore.uiui.utils.ServiceAliveUtils; import com.appstore.uiui.utils.ServiceAliveUtils;
import com.appstore.uiui.utils.Utils;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.task.DownloadTask; 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 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.init(this);
Aria.get(this).getDownloadConfig().setMaxTaskNum(1); Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
Aria.download(this).register(); Aria.download(this).register();
OKGO.getAllAppPackageName(handler); // OKGO.getAllAppPackageName(handler);
CheckUpdateBySNinfo(); CheckUpdateBySNinfo();
// startForeground(1, new Notification()); // startForeground(1, new Notification());
// 绑定建立链接 // 绑定建立链接
@@ -101,9 +107,9 @@ public class GuardService extends Service {
e.printStackTrace(); e.printStackTrace();
} }
if (null != packageInfo) { if (null != packageInfo) {
OKGO.checkUpdateByPackage(handler, packageInfo.packageName, String.valueOf(packageInfo.versionCode)); // OKGO.checkUpdateByPackage(handler, packageInfo.packageName, String.valueOf(packageInfo.versionCode));
} else { } 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) { switch (msg.what) {
case 200: case 200:
String url = (String) msg.obj; String url = (String) msg.obj;
getFile(url); // getFile(url);
break; break;
case 201: case 201:
String apppackage = (String) msg.obj; String apppackage = (String) msg.obj;
Log.e("fht", Settings.System.getString(getContentResolver(), "qch_app_forbid") + "?"); 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"); Log.e("fht", "app package write successful");
} }
break; break;
@@ -129,52 +135,80 @@ public class GuardService extends Service {
} }
}; };
private void getFile(String url) { // private void getFile(String url) {
OkGo.<File>get(url) // OkGo.<File>get(url)
.execute(new FileCallback() { // .execute(new FileCallback() {
@Override // @Override
public void onSuccess(final Response<File> response) { // public void onSuccess(final Response<File> response) {
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video"); //// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
new Thread(new Runnable() { // new Thread(new Runnable() {
@Override // @Override
public void run() { // public void run() {
ApkUtils.installApp(GuardService.this, response.body().getAbsolutePath()); // ApkUtils.installApp(GuardService.this, response.body().getAbsolutePath());
} // }
}).start(); // }).start();
LogUtils.e("getFile", "download file successful,now installing"); // LogUtils.e("getFile", "download file successful,now installing");
} // }
//
@Override // @Override
public void onError(Response<File> response) { // public void onError(Response<File> response) {
super.onError(response); // super.onError(response);
LogUtils.e("getFile", "File download Failure"); // LogUtils.e("getFile", "File download Failure");
} // }
//
@Override // @Override
public void downloadProgress(Progress progress) { // public void downloadProgress(Progress progress) {
super.downloadProgress(progress); // super.downloadProgress(progress);
LogUtils.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed); // LogUtils.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
} // }
}); // });
} // }
//在这里处理任务执行中的状态,如进度进度条的刷新 //在这里处理任务执行中的状态,如进度进度条的刷新
@Download.onTaskRunning @Download.onTaskRunning
protected void running(DownloadTask task) { protected void running(DownloadTask task) {
LogUtils.e("mjsheng", "我在下载=--------------::" + task.getState() + "-------" + task.getPercent() + "-------" + task.getExtendField()); LogUtils.e("mjsheng", "我在下载=--------------::" + task.getState() + "-------" + task.getPercent() + "-------" + task.getExtendField());
ToastUtils.showShort("我在下载=--------------::" + task.getExtendField() + "-------" + task.getPercent());
} }
@Download.onTaskComplete @Download.onTaskComplete
void taskComplete(DownloadTask task) { void taskComplete(DownloadTask task) {
//在这里处理任务完成的状态 //在这里处理任务完成的状态
final String downloadPath = task.getFilePath(); final String downloadPath = task.getFilePath();
String packageName = task.getExtendField(); if (null != task.getExtendField()) {
LogUtils.e("mjsheng", "downloadPath::" + downloadPath); JSONObject jsonObject = JSON.parseObject(task.getExtendField());
LogUtils.e("mjsheng", "extendField::" + packageName); String packageName = jsonObject.getString("app_package");
if (packageName.equalsIgnoreCase(this.getPackageName())) { File file = new File(downloadPath);
ApkUtils.installApp(this,downloadPath); int admin_id = (int) SPUtils.get(GuardService.this, "admin_id", -1);
} else { 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() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -182,6 +216,5 @@ public class GuardService extends Service {
} }
}).start(); }).start();
} }
}
} }

View File

@@ -36,15 +36,8 @@ import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; 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 class ApkUtils {
public static synchronized boolean getRootAhth() { public static synchronized boolean getRootAhth() {
Process process = null; Process process = null;
DataOutputStream os = null; DataOutputStream os = null;
@@ -115,6 +108,17 @@ public class ApkUtils {
} }
context.startActivity(intent); 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) { // public static void installRx(final Context context, final String packageName, final String filePath) {
//
Observable.create(new Observable.OnSubscribe<Integer>() { // Observable.create(new Observable.OnSubscribe<Integer>() {
@Override // @Override
public void call(Subscriber<? super Integer> subscriber) { // public void call(Subscriber<? super Integer> subscriber) {
File file = new File(filePath); // File file = new File(filePath);
if (filePath == null || filePath.length() == 0 || file == null) { // if (filePath == null || filePath.length() == 0 || file == null) {
Log.e("fanhuitong", "errormesg=========" + " 空啊 "); // Log.e("fanhuitong", "errormesg=========" + " 空啊 ");
subscriber.onNext(0); // subscriber.onNext(0);
return; // return;
} // }
// String[] args = { "pm", "install", "-r", filePath }; // // String[] args = { "pm", "install", "-r", filePath };
String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath}; // String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath};
// String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath; // // String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath;
Log.e("fanhuitong", "argss====" + args); // Log.e("fanhuitong", "argss====" + args);
ProcessBuilder processBuilder = new ProcessBuilder(args); // ProcessBuilder processBuilder = new ProcessBuilder(args);
Process process = null; // Process process = null;
BufferedReader successResult = null; // BufferedReader successResult = null;
BufferedReader errorResult = null; // BufferedReader errorResult = null;
StringBuilder successMsg = new StringBuilder(); // StringBuilder successMsg = new StringBuilder();
StringBuilder errorMsg = new StringBuilder(); // StringBuilder errorMsg = new StringBuilder();
try { // try {
process = processBuilder.start(); // process = processBuilder.start();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream())); // successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream())); // errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s; // String s;
while ((s = successResult.readLine()) != null) { // while ((s = successResult.readLine()) != null) {
Log.e("mjhseng", "successResult----------" + s); // Log.e("mjhseng", "successResult----------" + s);
successMsg.append(s); // successMsg.append(s);
} // }
while ((s = errorResult.readLine()) != null) { // while ((s = errorResult.readLine()) != null) {
Log.e("mjhseng", "errorResult----------" + s); // Log.e("mjhseng", "errorResult----------" + s);
errorMsg.append(s); // errorMsg.append(s);
} // }
} catch (IOException e1) { // } catch (IOException e1) {
Log.e("fanhuitong", "IOException e1)----------" + e1.toString()); // Log.e("fanhuitong", "IOException e1)----------" + e1.toString());
e1.printStackTrace(); // e1.printStackTrace();
} finally { // } finally {
try { // try {
if (successResult != null) { // if (successResult != null) {
successResult.close(); // successResult.close();
} // }
if (errorResult != null) { // if (errorResult != null) {
errorResult.close(); // errorResult.close();
} // }
} catch (IOException e1) { // } catch (IOException e1) {
Log.e("fanhuitong", "IOException e11)---------" + e1.toString()); // Log.e("fanhuitong", "IOException e11)---------" + e1.toString());
e1.printStackTrace(); // e1.printStackTrace();
} // }
if (process != null) { // if (process != null) {
process.destroy(); // process.destroy();
} // }
} // }
if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) { // if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) {
subscriber.onNext(2); // subscriber.onNext(2);
} else { // } else {
Log.e("fanhuitong", "errormesg=========" + errorMsg.toString()); // Log.e("fanhuitong", "errormesg=========" + errorMsg.toString());
subscriber.onNext(1); // subscriber.onNext(1);
} // }
} // }
}).subscribeOn(Schedulers.newThread()) // }).subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) // .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Integer>() { // .subscribe(new Observer<Integer>() {
//
@Override // @Override
public void onNext(Integer value) { // public void onNext(Integer value) {
if (value == 2) { // if (value == 2) {
//安装成功 // //安装成功
Utils.showToast(context, "安装成功"); // Utils.showToast(context, "安装成功");
Log.e("fanhuitong", "-----------安装成功-----------"); // Log.e("fanhuitong", "-----------安装成功-----------");
} else { // } else {
//安装错误 // //安装错误
Log.e("fanhuitong", "------------安装错误-----------"); // Log.e("fanhuitong", "------------安装错误-----------");
Utils.showToast(context, "安装失败"); // Utils.showToast(context, "安装失败");
} // }
} // }
//
@Override // @Override
public void onCompleted() { // public void onCompleted() {
//
} // }
//
@Override // @Override
public void onError(Throwable e) { // public void onError(Throwable e) {
//安装错误 // //安装错误
} // }
}); // });
} // }
public static void installApp(Context context, String filePath) { public static void installApp(Context context, String filePath) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
@@ -595,5 +599,37 @@ public class ApkUtils {
return name; 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;
}
}
} }

View 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";
}
}

View File

@@ -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;
}
}

View File

@@ -120,5 +120,23 @@ public class StorageUtils {
return "" + (size) + "KB"; 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);
}
}
} }

View File

@@ -33,8 +33,11 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import com.alibaba.fastjson.JSONObject;
import com.appstore.uiui.R; import com.appstore.uiui.R;
import com.arialyy.aria.core.Aria;
import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
@@ -49,103 +52,12 @@ import java.util.List;
public class Utils { 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; protected static Toast toast = null;
private static String oldMsg; private static String oldMsg;
private static long oneTime = 0; private static long oneTime = 0;
private static long twoTime = 0; private static long twoTime = 0;
// 积分记录 达人标准次数记录
// MD5 设备地址标识 // MD5 设备地址标识
// public static String getMAC(Context context) { // public static String getMAC(Context context) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // 如果当前设备系统大于等于6.0 使用下面的方法 // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // 如果当前设备系统大于等于6.0 使用下面的方法
@@ -797,4 +709,7 @@ public class Utils {
return bitmap; return bitmap;
} }
} }

View 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>

View File

@@ -112,7 +112,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:overScrollMode="never" android:overScrollMode="never"
android:scrollbars="none"> android:scrollbars="none"
android:visibility="gone">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/detail_rv_image" android:id="@+id/detail_rv_image"
@@ -131,6 +132,7 @@
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:text="应用介绍" android:text="应用介绍"
android:textSize="@dimen/sp_16" android:textSize="@dimen/sp_16"
android:visibility="gone"
android:textStyle="bold"> android:textStyle="bold">
</TextView> </TextView>
@@ -152,6 +154,7 @@
android:layout_marginTop="@dimen/dp_2" android:layout_marginTop="@dimen/dp_2"
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:text="更新" android:text="更新"
android:visibility="gone"
android:textSize="@dimen/sp_16" android:textSize="@dimen/sp_16"
android:textStyle="bold"> android:textStyle="bold">
@@ -175,6 +178,7 @@
android:layout_marginTop="@dimen/dp_2" android:layout_marginTop="@dimen/dp_2"
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:text="信息" android:text="信息"
android:visibility="gone"
android:textSize="@dimen/sp_16" android:textSize="@dimen/sp_16"
android:textStyle="bold"> android:textStyle="bold">
@@ -195,6 +199,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_15" android:layout_marginLeft="@dimen/dp_15"
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:visibility="gone"
android:text="版本" /> android:text="版本" />
<TextView <TextView
@@ -203,6 +208,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_15" android:layout_marginLeft="@dimen/dp_15"
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:visibility="gone"
android:text="时间" /> android:text="时间" />
<TextView <TextView
@@ -211,6 +217,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_15" android:layout_marginLeft="@dimen/dp_15"
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:visibility="gone"
android:text="开发者" /> android:text="开发者" />

View File

@@ -36,6 +36,7 @@
android:layout_marginStart="20dp" android:layout_marginStart="20dp"
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:visibility="gone"
android:layout_weight="1"> android:layout_weight="1">

View File

@@ -35,7 +35,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1.5" android:layout_weight="1.5"
android:gravity="center_vertical" android:gravity="bottom"
android:singleLine="true" android:singleLine="true"
android:text="今日头条" android:text="今日头条"
android:textColor="@color/black" android:textColor="@color/black"
@@ -48,6 +48,7 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:singleLine="true" android:singleLine="true"
android:text="北京字节跳动网络技术有限公司" android:text="北京字节跳动网络技术有限公司"
android:visibility="gone"
android:textSize="12sp" /> android:textSize="12sp" />
@@ -78,7 +79,7 @@
android:stateListAnimator="@null" android:stateListAnimator="@null"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:background="@drawable/btn_style_none" android:background="@drawable/btn_shap_download"
android:text="下载中" android:text="下载中"
android:textSize="@dimen/sp_16" android:textSize="@dimen/sp_16"
android:visibility="visible" /> android:visibility="visible" />

View File

@@ -112,7 +112,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:overScrollMode="never" android:overScrollMode="never"
android:scrollbars="none"> android:scrollbars="none"
android:visibility="gone">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/detail_rv_image" android:id="@+id/detail_rv_image"
@@ -131,6 +132,7 @@
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:text="应用介绍" android:text="应用介绍"
android:textSize="@dimen/sp_16" android:textSize="@dimen/sp_16"
android:visibility="gone"
android:textStyle="bold"> android:textStyle="bold">
</TextView> </TextView>
@@ -153,6 +155,7 @@
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:text="更新" android:text="更新"
android:textSize="@dimen/sp_16" android:textSize="@dimen/sp_16"
android:visibility="gone"
android:textStyle="bold"> android:textStyle="bold">
</TextView> </TextView>
@@ -176,6 +179,7 @@
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:text="信息" android:text="信息"
android:textSize="@dimen/sp_16" android:textSize="@dimen/sp_16"
android:visibility="gone"
android:textStyle="bold"> android:textStyle="bold">
</TextView> </TextView>
@@ -195,6 +199,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_15" android:layout_marginLeft="@dimen/dp_15"
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:visibility="gone"
android:text="版本" /> android:text="版本" />
<TextView <TextView
@@ -203,6 +208,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_15" android:layout_marginLeft="@dimen/dp_15"
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:visibility="gone"
android:text="时间" /> android:text="时间" />
<TextView <TextView
@@ -211,6 +217,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_15" android:layout_marginLeft="@dimen/dp_15"
android:layout_marginRight="@dimen/dp_15" android:layout_marginRight="@dimen/dp_15"
android:visibility="gone"
android:text="开发者" /> android:text="开发者" />

View File

@@ -36,6 +36,7 @@
android:layout_marginStart="20dp" android:layout_marginStart="20dp"
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:visibility="gone"
android:layout_weight="1"> android:layout_weight="1">

View File

@@ -35,7 +35,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1.5" android:layout_weight="1.5"
android:gravity="center_vertical" android:gravity="bottom"
android:singleLine="true" android:singleLine="true"
android:text="今日头条" android:text="今日头条"
android:textColor="@color/black" android:textColor="@color/black"
@@ -48,6 +48,7 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:singleLine="true" android:singleLine="true"
android:text="北京字节跳动网络技术有限公司" android:text="北京字节跳动网络技术有限公司"
android:visibility="gone"
android:textSize="12sp" /> android:textSize="12sp" />
@@ -78,7 +79,7 @@
android:stateListAnimator="@null" android:stateListAnimator="@null"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:background="@drawable/btn_style_none" android:background="@drawable/btn_shap_download"
android:text="下载中" android:text="下载中"
android:textSize="@dimen/sp_16" android:textSize="@dimen/sp_16"
android:visibility="visible" /> android:visibility="visible" />

View File

@@ -15,4 +15,6 @@
<color name="search">#F1F1F1</color> <color name="search">#F1F1F1</color>
<color name="red">#d64743</color> <color name="red">#d64743</color>
<color name="blue">#00a0e9</color> <color name="blue">#00a0e9</color>
<color name="adapter_selector_default">#E9E9E9</color>
</resources> </resources>