version:1.0.0
update:更换包名 bugfixes:
This commit is contained in:
146
app/src/main/java/com/xxpatx/os/adapter/DailyAppAdapter.java
Normal file
146
app/src/main/java/com/xxpatx/os/adapter/DailyAppAdapter.java
Normal file
@@ -0,0 +1,146 @@
|
||||
package com.xxpatx.os.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
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.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.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.class.getSimpleName();
|
||||
|
||||
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);
|
||||
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) {
|
||||
ApkUtils.openPackage(mContext, dailyAppBean.getPackageName(), dailyAppBean.getClassName());
|
||||
AppUsedTimeUtils.getInstance().setAppPackageName(dailyAppBean.getPackageName());
|
||||
AppUsedTimeUtils.getInstance().setStartTime(System.currentTimeMillis());
|
||||
// SendRunningApp(mContext);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void SendRunningApp(Context context) {
|
||||
String packageName = AppUsedTimeUtils.getInstance().getAppPackageName();
|
||||
long time = AppUsedTimeUtils.getInstance().getStartTime();
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("app_package", packageName);
|
||||
jsonObject.addProperty("version_name", ApkUtils.getAPPVersionName(context, packageName));
|
||||
jsonObject.addProperty("start_time", time / 1000);
|
||||
String jsonString = jsonObject.toString();
|
||||
Log.e(TAG, "SendRunningApp: " + jsonString);
|
||||
NetInterfaceManager.getInstance()
|
||||
.getRunningAppObservable(jsonString)
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("SendRunningApp", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("SendRunningApp", "onSubscribe: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("SendRunningApp", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("SendRunningApp", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user