update:2019.12.03

fix:
add:更新在fragment中接收广播消息更新界面
This commit is contained in:
2019-12-06 09:39:06 +08:00
parent 94aa3a7d86
commit 2653b91e70
19 changed files with 245 additions and 65 deletions

View File

@@ -47,7 +47,9 @@
<activity android:name=".activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

View File

@@ -12,8 +12,10 @@ import android.util.Log;
import androidx.annotation.NonNull;
import com.appstore.uiui.jpush.Logger;
import com.appstore.uiui.network.OKGOPost;
import com.appstore.uiui.utils.ApkUtils;
import com.appstore.uiui.utils.LogUtils;
import com.appstore.uiui.utils.SPUtils;
import com.appstore.uiui.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.FileCallback;
@@ -329,9 +331,9 @@ public class MyApplication extends Application {
PackageManager pm = getPackageManager();
//后台为0可能传过来null
if (is_lock == 1) {
pm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
} else {
pm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
} else {
pm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
}
} catch (JSONException e) {
e.printStackTrace();
@@ -379,12 +381,17 @@ public class MyApplication extends Application {
}
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(getAppContext().getPackageName())) {
ApkUtils.deleteApkInSilence(packageName);
if (!packageName.equals("") && !packageName.equals(getApplicationContext().getPackageName())) {
if (!ApkUtils.isAvailable(getApplicationContext(), packageName)) {
OKGOPost.setAppuninstallInfo(sn_id, packageName);
} else {
ApkUtils.deleteApkInSilence(packageName);
}
}
} catch (JSONException e) {
e.printStackTrace();

View File

@@ -1,18 +1,28 @@
package com.appstore.uiui.activity;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Adapter;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.appstore.uiui.R;
import com.appstore.uiui.adapter.AppAdapter;
import com.appstore.uiui.adapter.DownloadManagerAdapter;
import com.appstore.uiui.base.BaseActivity;
import com.appstore.uiui.bean.AppInfo;
import com.appstore.uiui.utils.ApkUtils;
import com.appstore.uiui.utils.ToastUtil;
import com.lzy.okgo.model.Progress;
import com.lzy.okserver.OkDownload;
import com.lzy.okserver.download.DownloadListener;
import com.lzy.okserver.task.XExecutor;
import java.io.File;
public class DownloadManagerActivity extends BaseActivity implements XExecutor.OnAllTaskEndListener {
private RecyclerView recyclerView;
private DownloadManagerAdapter adapter;
@@ -31,8 +41,8 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
@Override
protected void initData() {
okDownload = OkDownload.getInstance();
adapter = new DownloadManagerAdapter(this);
adapter.updateData(DownloadManagerAdapter.TYPE_ALL);
adapter = new DownloadManagerAdapter(this, handler);
adapter.updateData(DownloadManagerAdapter.TYPE_ING);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
okDownload.addOnAllTaskEndListener(this);
@@ -47,6 +57,8 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
@Override
public void onAllTaskEnd() {
ToastUtil.show("所有任务已完成");
adapter.notifyDataSetChanged();
}
@Override
@@ -65,4 +77,17 @@ public class DownloadManagerActivity extends BaseActivity implements XExecutor.O
public void finish(View view) {
this.finish();
}
private Handler handler = new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if (msg.what == 100) {
adapter.updateData(DownloadManagerAdapter.TYPE_ING);
adapter.notifyDataSetChanged();
}
}
};
}

View File

@@ -82,6 +82,9 @@ public class LocalManagerActivity extends BaseActivity implements RefreshManager
LocalApp bean = new LocalApp();
bean.setAppName(resolveInfoList.get(i).loadLabel(getApplicationContext().getPackageManager()).toString());
String packageName = resolveInfoList.get(i).activityInfo.packageName;
if (packageName.equals(getApplicationContext().getPackageName())||packageName.equals("com.android.uiuios")){
continue;
}
bean.setPackageName(packageName);
Drawable icon = resolveInfoList.get(i).loadIcon(getApplicationContext().getPackageManager());
bean.setIcon(icon);

View File

@@ -1,7 +1,9 @@
package com.appstore.uiui.adapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.telecom.Call;
import android.view.LayoutInflater;
import android.view.View;
@@ -18,7 +20,9 @@ import com.appstore.uiui.R;
import com.appstore.uiui.activity.DetailsActivity;
import com.appstore.uiui.bean.AppInfo;
import com.appstore.uiui.listener.LogDownloadListener;
import com.appstore.uiui.network.OKGOPost;
import com.appstore.uiui.utils.ApkUtils;
import com.appstore.uiui.utils.LogUtils;
import com.appstore.uiui.utils.ToastUtil;
import com.bumptech.glide.Glide;
import com.lzy.okgo.OkGo;
@@ -45,6 +49,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
private boolean isNotLoadBitmap = false;
//order代表是否显示所在的位置1.2.3.
public AppAdapter(List<AppInfo> appInfoList, boolean isShowOrder, Context context) {
this.mContext = context;
@@ -60,6 +65,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
@Override
public void onBindViewHolder(Holder holder, final int position) {
final AppInfo appInfo = mAppInfoList.get(position);
final DownloadTask downloadTask = OkDownload.getInstance().getTask(appInfo.getApp_url());
holder.setTag(appInfo.getApp_url());
@@ -81,6 +87,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
} else {
holder.tvName.setText(appInfo.getApp_name());
}
holder.tvSize.setText(appInfo.getApp_size() + "M");
holder.ratingBar.setRating((float) appInfo.getApp_score());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
@@ -95,11 +102,17 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
if (appInfo.isInstall()) {
if (appInfo.isUpdate()) {
holder.btnDownLoad.setText("更新");
holder.btnDownLoad.setTextColor(mContext.getColor(R.color.green));
holder.btnDownLoad.setBackground(mContext.getDrawable(R.drawable.btn_style_none));
} else {
holder.btnDownLoad.setText("打开");
holder.btnDownLoad.setTextColor(mContext.getColor(R.color.black));
holder.btnDownLoad.setBackground(mContext.getDrawable(R.drawable.btn_style_open));
}
} else {
holder.btnDownLoad.setText("下载");
holder.btnDownLoad.setTextColor(mContext.getColor(R.color.green));
holder.btnDownLoad.setBackground(mContext.getDrawable(R.drawable.btn_style_none));
if (downloadTask != null) {
holder.refresh(downloadTask.progress);
}
@@ -141,11 +154,10 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
public class Holder extends RecyclerView.ViewHolder {
ImageView ivIcon;
TextView tvCompany, tvName;
TextView tvCompany, tvName, tvSize;
Button btnDownLoad;
RatingBar ratingBar;
// TextView tvInstalled;
CardView cardView;
private DownloadTask task;
private String tag;
@@ -155,10 +167,10 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
ivIcon = itemView.findViewById(R.id.app_iv_icon);
tvCompany = itemView.findViewById(R.id.app_tv_company);
tvName = itemView.findViewById(R.id.app_tv_name);
tvSize = itemView.findViewById(R.id.app_tv_size);
btnDownLoad = itemView.findViewById(R.id.app_btn_download);
ratingBar = itemView.findViewById(R.id.app_rating_bar);
// tvInstalled = itemView.findViewById(R.id.app_tv_installed);
cardView = itemView.findViewById(R.id.app_card_view);
}
public void bind() {
@@ -180,7 +192,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
btnDownLoad.setText("等待");
break;
case Progress.FINISH:
btnDownLoad.setText("完成");
btnDownLoad.setText("安装中");
break;
case Progress.LOADING:
btnDownLoad.setText((int) (progress.fraction * 100) + "%");
@@ -202,6 +214,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
}
}
public void setNotLoadBitmap(boolean isNotLoadBitmap) {
this.isNotLoadBitmap = isNotLoadBitmap;
notifyDataSetChanged();

View File

@@ -1,6 +1,7 @@
package com.appstore.uiui.adapter;
import android.content.Context;
import android.os.Handler;
import android.text.format.Formatter;
import android.view.LayoutInflater;
import android.view.View;
@@ -40,10 +41,12 @@ public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManager
private int type;
private final LayoutInflater mInflater;
private Handler mhandler;
public DownloadManagerAdapter(Context context) {
public DownloadManagerAdapter(Context context, Handler handler) {
this.mContext = context;
mInflater = LayoutInflater.from(mContext);
this.mhandler = handler;
}
public void updateData(int type) {
@@ -241,11 +244,12 @@ public class DownloadManagerAdapter extends RecyclerView.Adapter<DownloadManager
@Override
public void onFinish(File file, Progress progress) {
mhandler.sendEmptyMessage(100);
}
@Override
public void onRemove(Progress progress) {
}
}

View File

@@ -78,7 +78,6 @@ public class LocalAppAdapter extends RecyclerView.Adapter<LocalAppAdapter.LocalA
TextView tvCompany, tvName, tvVersion;
TextView tvUpdate;
Button btnDownLoad;
CardView cardView;
public LocalAppViewHolder(View itemView) {
super(itemView);
@@ -88,7 +87,6 @@ public class LocalAppAdapter extends RecyclerView.Adapter<LocalAppAdapter.LocalA
tvVersion = itemView.findViewById(R.id.local_app_version);
tvUpdate = itemView.findViewById(R.id.local_app_update);
btnDownLoad = itemView.findViewById(R.id.local_app_btn_download);
cardView = itemView.findViewById(R.id.local_app_card_view);
}
}
}

View File

@@ -59,6 +59,8 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
holder.tvName.setText(appInfo.getAppName());
holder.tvVersion.setText(appInfo.getVersionName() + "->" + appInfo.getNewVersionName());
holder.btnDownLoad.setText("更新");
holder.btnDownLoad.setTextColor(context.getColor(R.color.green));
holder.btnDownLoad.setBackground(context.getDrawable(R.drawable.btn_style_none));
holder.btnDownLoad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -96,7 +98,6 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
TextView tvName, tvVersion;
TextView tvUpdate;
Button btnDownLoad;
CardView cardView;
private DownloadTask task;
private String tag;
@@ -108,7 +109,6 @@ public class UpdateAppAdapter extends RecyclerView.Adapter<UpdateAppAdapter.Upda
tvVersion = itemView.findViewById(R.id.local_app_version);
tvUpdate = itemView.findViewById(R.id.local_app_update);
btnDownLoad = itemView.findViewById(R.id.local_app_btn_download);
cardView = itemView.findViewById(R.id.local_app_card_view);
}
public void bind() {

View File

@@ -1,5 +1,9 @@
package com.appstore.uiui.fragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -43,17 +47,46 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
private SmartRefreshLayout mRefreshLayout;
private List<AppInfos> appInfoList;//
private List<AppInfo> newAppInfoList;
private List<AppInfo> newAppInfoList=new ArrayList<>();
private AppAdapter adapter;
private boolean isNotLoadBitmap;
private installReceiver myReceiver;
@Override
public int getLayoutId() {
return R.layout.fragment_featured;
}
@Override
public void onStop() {
super.onStop();
if (myReceiver != null) {
try {
getActivity().getApplication().unregisterReceiver(myReceiver);
} catch (Exception e) {
LogUtils.e("onStop", e.getMessage());
}
}
}
@Override
public void onStart() {
super.onStart();
adapter.setData(checkUpdateOrInstalled(newAppInfoList));
adapter.notifyDataSetChanged();
if (myReceiver == null) {
myReceiver = new installReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("com.appstore.uiui.PACKAGE_ADDED");
filter.addAction("com.appstore.uiui.PACKAGE_REPLACED");
filter.addAction("com.appstore.uiui.PACKAGE_REMOVED");
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
getActivity().getApplication().registerReceiver(myReceiver, filter);
}
}
@Override
public void initViews(View view) {
mRvResult = view.findViewById(R.id.featured_rv_result);
@@ -62,7 +95,7 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
isNotLoadBitmap = false;
newAppInfoList = new ArrayList<>();
adapter = new AppAdapter(newAppInfoList, false, getContext());
adapter.setHasStableIds(true);
mRvResult.setAdapter(adapter);
@@ -126,4 +159,17 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
return list;
}
public class installReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
//接收安装广播
if (action.equals("com.appstore.uiui.PACKAGE_ADDED") || action.equals("com.appstore.uiui.PACKAGE_REMOVED") || action.equals("com.appstore.uiui.PACKAGE_REPLACED")) {
adapter.setData(checkUpdateOrInstalled(newAppInfoList));
adapter.notifyDataSetChanged();
}
}
}
}

View File

@@ -161,7 +161,7 @@ public class ManageFragment extends LazyLoadFragment {
applist = (List<AppInfo>) msg.obj;
updateDta(applist);
updateNum = updateAppInfoList.size();
manage_tv_updateNum.setText(updateNum + "个应用可以升级");
manage_tv_updateNum.setText(updateNum + "");
adapter.notifyDataSetChanged();
break;
}

View File

@@ -25,12 +25,19 @@ public class AppManagerReceiver extends BroadcastReceiver {
action = intent.getAction();
//接收安装广播
if (action.equals(Intent.ACTION_PACKAGE_ADDED) || action.equals(Intent.ACTION_PACKAGE_REPLACED)) {
if (action.equals(Intent.ACTION_PACKAGE_ADDED)){
Intent intents = new Intent("com.appstore.uiui.PACKAGE_ADDED");
context.sendBroadcast(intents);
}else {
Intent intents = new Intent("com.appstore.uiui.PACKAGE_REPLACED");
context.sendBroadcast(intents);
}
String packageName = intent.getDataString().replace("package:", "");
String name = ApkUtils.getApplicationName(context, packageName);
ToastUtil.show(name + ":安装成功");
LogUtils.e(TAG, "安装了:" + packageName + "包名的程序");
// ToastTool.show("安装成功");
if (!packageName.equals(context.getPackageName())) {
if (!packageName.equals(context.getPackageName())&&!packageName.equals("com.android.uiuios")) {
if (member_id == -1 || sn_id.equals("-1")) {
OKGOPost.getUserInfo(context);
} else {
@@ -43,7 +50,9 @@ public class AppManagerReceiver extends BroadcastReceiver {
if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) {
String packageName = intent.getDataString().replace("package:", "");
LogUtils.e(TAG, "卸载了:" + packageName + "包名的程序");
if (!packageName.equals(context.getPackageName())) {
Intent intents = new Intent("com.appstore.uiui.PACKAGE_REMOVED");
context.sendBroadcast(intents);
if (!packageName.equals(context.getPackageName())&&!packageName.equals("com.android.uiuios")) {
if (member_id == -1 || sn_id.equals("-1")) {
OKGOPost.getUserInfo(context);
} else {

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 连框颜色值 -->
<item>
<shape>
<solid android:color="#55b68a" />
<corners android:radius="@dimen/dp_25" />
</shape>
</item>
<!-- 主体背景颜色值 -->
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape>
<gradient
android:angle="90"
android:centerColor="#FFFFFF"
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#FFFFFF"
android:startColor="#FFFFFF"
android:type="linear" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
<!-- 应该是圆角 -->
<corners android:radius="@dimen/dp_25" />
</shape>
</item>
</layer-list>

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 连框颜色值 -->
<item>
<shape>
<solid android:color="#000000" />
<corners android:radius="@dimen/dp_25" />
</shape>
</item>
<!-- 主体背景颜色值 -->
<item
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape>
<gradient
android:angle="90"
android:centerColor="#FFFFFF"
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#FFFFFF"
android:startColor="#FFFFFF"
android:type="linear" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
<!-- 应该是圆角 -->
<corners android:radius="@dimen/dp_25" />
</shape>
</item>
</layer-list>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 291 B

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -28,34 +28,36 @@
android:background="@drawable/ic_kind_detail" />
</LinearLayout>
<include layout="@layout/include_line_horizontal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="可升级应用"
android:textSize="10sp" />
<TextView
android:id="@+id/manage_tv_updateNum"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_width="@dimen/dp_40"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="0个应用可以升级"
android:textColor="@color/black"
android:textSize="16sp" />
android:text="0"
android:textSize="10sp"
/>
</LinearLayout>
<include layout="@layout/include_line_horizontal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="可升级应用"
android:textSize="10sp" />
<include layout="@layout/include_line_horizontal" />

View File

@@ -27,7 +27,7 @@
<LinearLayout
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_height="70dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
@@ -52,6 +52,15 @@
android:textSize="12sp" />
<TextView
android:id="@+id/app_tv_size"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:singleLine="true"
android:text="1.00M"
android:textSize="12sp" />
<RatingBar
android:id="@+id/app_rating_bar"
@@ -60,23 +69,20 @@
android:layout_height="wrap_content" />
</LinearLayout>
<androidx.cardview.widget.CardView
android:id="@+id/app_card_view"
android:layout_width="55dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
app:cardCornerRadius="5dp">
<Button
android:id="@+id/app_btn_download"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="@dimen/dp_40"
android:layout_height="@dimen/dp_20"
android:textColor="#55b68a"
android:stateListAnimator="@null"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_selector"
android:text="下载"
android:layout_marginRight="10dp"
android:background="@drawable/btn_style_none"
android:text="下载中"
android:textSize="@dimen/sp_10"
android:visibility="visible" />
</androidx.cardview.widget.CardView>
<TextView

View File

@@ -18,7 +18,7 @@
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:background="@mipmap/ic_launcher_round" />
/>
<TextView
android:id="@+id/kind_tv_name"

View File

@@ -60,23 +60,16 @@
</LinearLayout>
<androidx.cardview.widget.CardView
android:id="@+id/local_app_card_view"
android:layout_width="55dp"
android:layout_height="35dp"
<Button
android:id="@+id/local_app_btn_download"
android:layout_width="@dimen/dp_40"
android:layout_height="@dimen/dp_20"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_style_open"
android:layout_marginRight="10dp"
app:cardCornerRadius="5dp">
<Button
android:id="@+id/local_app_btn_download"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_selector"
android:text="删除"
android:visibility="visible" />
</androidx.cardview.widget.CardView>
android:stateListAnimator="@null"
android:text="删除"
android:visibility="visible" />
<TextView

View File

@@ -9,5 +9,5 @@
<color name="gray">#c1bcbc</color>
<color name="download">#d9d9d9</color>
<color name="backgroundcolor">#d4d0d0</color>
<color name="green">#55b68a</color>
</resources>