139 lines
4.9 KiB
Java
139 lines
4.9 KiB
Java
package com.xxpatx.os.adapter;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.util.Log;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.google.gson.JsonObject;
|
|
import com.xxpatx.os.R;
|
|
import com.xxpatx.os.activity.service.ServiceActivity;
|
|
import com.xxpatx.os.bean.BaseResponse;
|
|
import com.xxpatx.os.bean.DailyAppBean;
|
|
import com.xxpatx.os.dialog.DailyAppDialog;
|
|
import com.xxpatx.os.manager.AppStatusManager;
|
|
import com.xxpatx.os.network.NetInterfaceManager;
|
|
import com.xxpatx.os.service.NotificationService;
|
|
import com.xxpatx.os.utils.ApkUtils;
|
|
import com.xxpatx.os.utils.AppUsedTimeUtils;
|
|
|
|
import java.util.List;
|
|
|
|
import io.reactivex.rxjava3.core.Observer;
|
|
import io.reactivex.rxjava3.disposables.Disposable;
|
|
|
|
public class DailyAppAdapter extends RecyclerView.Adapter<DailyAppAdapter.Holder> {
|
|
private static final String TAG = "DailyAppAdapter";
|
|
|
|
private Context mContext;
|
|
private List<DailyAppBean> mDailyAppBeans;
|
|
|
|
public void setDailyAppBeans(List<DailyAppBean> appSelectBeanList) {
|
|
this.mDailyAppBeans = appSelectBeanList;
|
|
notifyDataSetChanged();
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
mContext = parent.getContext();
|
|
return new Holder(LayoutInflater.from(mContext).inflate(R.layout.item_daily_app, parent, false));
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(@NonNull Holder holder, int position) {
|
|
DailyAppBean dailyAppBean = mDailyAppBeans.get(position);
|
|
String packageName = dailyAppBean.getPackageName();
|
|
switch (packageName) {
|
|
case "xxpatx.os.service":
|
|
holder.iv_icon.setImageDrawable(mContext.getDrawable(R.drawable.icon_wechat_service));
|
|
break;
|
|
default:
|
|
holder.iv_icon.setImageDrawable(dailyAppBean.getIcon(mContext));
|
|
}
|
|
holder.tv_name.setText(dailyAppBean.getAppName());
|
|
holder.root.setOnLongClickListener(new View.OnLongClickListener() {
|
|
@Override
|
|
public boolean onLongClick(View view) {
|
|
showDialog(dailyAppBean);
|
|
return false;
|
|
}
|
|
});
|
|
holder.root.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
switch (packageName) {
|
|
case "xxpatx.os.service":
|
|
mContext.startActivity(new Intent(mContext, ServiceActivity.class));
|
|
break;
|
|
default:
|
|
ApkUtils.openPackage(mContext, packageName, dailyAppBean.getClassName());
|
|
AppUsedTimeUtils.getInstance().setAppPackageName(packageName);
|
|
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
|
}
|
|
}
|
|
});
|
|
int size = NotificationService.getNotificationLength(packageName);
|
|
if (size == 0) {
|
|
holder.bg.setVisibility(View.GONE);
|
|
} else if (size < 99) {
|
|
holder.bg.setVisibility(View.VISIBLE);
|
|
holder.bg.setText(String.valueOf(size));
|
|
} else {
|
|
holder.bg.setVisibility(View.VISIBLE);
|
|
holder.bg.setText("99+");
|
|
}
|
|
}
|
|
|
|
|
|
private void showDialog(DailyAppBean dailyAppBean) {
|
|
DailyAppDialog dailyAppDialog = new DailyAppDialog(mContext);
|
|
dailyAppDialog.setTitle("放到桌面");
|
|
dailyAppDialog.setMessage(dailyAppBean.getAppName());
|
|
dailyAppDialog.setIconImage(dailyAppBean.getIcon(mContext));
|
|
dailyAppDialog.setOnClickBottomListener(new DailyAppDialog.OnClickBottomListener() {
|
|
@Override
|
|
public void onPositiveClick() {
|
|
AppStatusManager.getInstance().removeHidedApp(dailyAppBean.getPackageName());
|
|
mDailyAppBeans.remove(dailyAppBean);
|
|
notifyDataSetChanged();
|
|
dailyAppDialog.dismiss();
|
|
}
|
|
|
|
@Override
|
|
public void onNegtiveClick() {
|
|
dailyAppDialog.dismiss();
|
|
}
|
|
});
|
|
dailyAppDialog.show();
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return mDailyAppBeans == null ? 0 : mDailyAppBeans.size();
|
|
}
|
|
|
|
static class Holder extends RecyclerView.ViewHolder {
|
|
ConstraintLayout root;
|
|
ImageView iv_icon;
|
|
TextView tv_name;
|
|
TextView bg;
|
|
|
|
Holder(@NonNull View itemView) {
|
|
super(itemView);
|
|
root = itemView.findViewById(R.id.root);
|
|
iv_icon = itemView.findViewById(R.id.iv_icon);
|
|
tv_name = itemView.findViewById(R.id.tv_name);
|
|
bg = itemView.findViewById(R.id.bg);
|
|
}
|
|
}
|
|
}
|