Skip to content

Commit

Permalink
* [Issue #1] Application crashes (immediately) after choosing ' View …
Browse files Browse the repository at this point in the history
…log' from the menu.

Addressed a couple of lint warnings.
  • Loading branch information
amaa-99 committed Jul 30, 2023
1 parent c4732ab commit f65f3ef
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.text.DateFormat;
Expand All @@ -32,10 +33,7 @@ public class LogRecyclerViewAdapter extends RecyclerView.Adapter<LogRecyclerView

private final List<LogData> logData;
private final Context context;
private LogData data;
private PackageInfo info;
private final RecyclerItemClickListener recyclerItemClickListener;
private View mView;

public LogRecyclerViewAdapter(final Context context, RecyclerItemClickListener recyclerItemClickListener) {
this.context = context;
Expand All @@ -48,9 +46,10 @@ public void updateData(List<LogData> logDataList) {
logData.addAll(logDataList);
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.log_recycle_item, parent, false);
View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.log_recycle_item, parent, false);
return new ViewHolder(mView);
}

Expand Down Expand Up @@ -100,12 +99,12 @@ private Bitmap getAppIcon26(PackageManager mPackageManager, ApplicationInfo appl

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
data = logData.get(position);
LogData data = logData.get(position);
PackageManager manager = context.getPackageManager();
holder.bind(logData.get(position),recyclerItemClickListener);
holder.bind(logData.get(position), recyclerItemClickListener);
try {
HashMap<Integer,String> listMaps = Api.getPackagesForUser(Api.getListOfUids());
info = Api.getPackageDetails(context, listMaps, data.getUid());
HashMap<Integer, String> listMaps = Api.getPackagesForUser(Api.getListOfUids());
PackageInfo info = Api.getPackageDetails(context, listMaps, data.getUid());
if(info!=null && info.applicationInfo !=null) {
Object drawable = info.applicationInfo.loadIcon(manager);
if (drawable instanceof Bitmap)
Expand All @@ -117,17 +116,16 @@ public void onBindViewHolder(ViewHolder holder, int position) {
holder.icon.setImageBitmap(Api.getBitmapFromDrawable(appIcon));
}
} catch (Exception e) {
Log.e(TAG,e.getMessage(),e);
info = null;
Log.e(TAG, e.getMessage(), e);
try {
if(Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.O) {
holder.icon.setBackground(context.getDrawable(R.drawable.ic_unknown));
} else {
Drawable appIcon = context.getDrawable(R.drawable.ic_unknown);
holder.icon.setImageBitmap(Api.getBitmapFromDrawable(appIcon));
}
}catch (Exception e1) {
Log.e(TAG,e1.getMessage(),e1);
} catch (Exception e1) {
Log.e(TAG, e1.getMessage(), e1);
}
}
try {
Expand Down

0 comments on commit f65f3ef

Please sign in to comment.