|
| 1 | +package it.pgp.xfiles.adapters; |
| 2 | + |
| 3 | +import android.content.Context; |
| 4 | +import android.support.annotation.Nullable; |
| 5 | +import android.view.LayoutInflater; |
| 6 | +import android.view.View; |
| 7 | +import android.view.ViewGroup; |
| 8 | +import android.widget.BaseAdapter; |
| 9 | +import android.widget.TextView; |
| 10 | + |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +import it.pgp.xfiles.R; |
| 14 | +import it.pgp.xfiles.enums.FileOpsErrorCodes; |
| 15 | +import it.pgp.xfiles.utils.pathcontent.BasePathContent; |
| 16 | + |
| 17 | +public class ExtractResultsAdapter extends BaseAdapter { |
| 18 | + private final Context context; |
| 19 | + private final LayoutInflater inflater; |
| 20 | + private final List<BasePathContent> srcArchives; |
| 21 | + private final List<FileOpsErrorCodes> results; |
| 22 | + |
| 23 | + public ExtractResultsAdapter(Context context, List<BasePathContent> srcArchives, List<FileOpsErrorCodes> results) { |
| 24 | + this.context = context; |
| 25 | + this.inflater = LayoutInflater.from(context); |
| 26 | + this.srcArchives = srcArchives; |
| 27 | + this.results = results; |
| 28 | + } |
| 29 | + |
| 30 | + public static class ExtractResultsViewHolder { |
| 31 | + public TextView srcArchive, result; |
| 32 | + |
| 33 | + ExtractResultsViewHolder(TextView srcArchive, TextView result) { |
| 34 | + this.srcArchive = srcArchive; |
| 35 | + this.result = result; |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public int getCount() { |
| 41 | + return srcArchives.size(); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public Object getItem(int position) { |
| 46 | + return null; |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public long getItemId(int position) { |
| 51 | + return position; |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public View getView(int position, @Nullable View convertView, ViewGroup parent) { |
| 56 | + TextView srcArchive, result; |
| 57 | + |
| 58 | + if(convertView == null) { |
| 59 | + convertView = inflater.inflate(R.layout.extract_results_item, null); |
| 60 | + |
| 61 | + srcArchive = convertView.findViewById(R.id.extract_results_srcArchive); |
| 62 | + result = convertView.findViewById(R.id.extract_results_result); |
| 63 | + |
| 64 | + convertView.setTag(new ExtractResultsAdapter.ExtractResultsViewHolder(srcArchive,result)); |
| 65 | + } |
| 66 | + else { |
| 67 | + ExtractResultsAdapter.ExtractResultsViewHolder viewHolder = (ExtractResultsAdapter.ExtractResultsViewHolder) convertView.getTag(); |
| 68 | + srcArchive = viewHolder.srcArchive; |
| 69 | + result = viewHolder.result; |
| 70 | + } |
| 71 | + |
| 72 | + srcArchive.setText(srcArchives.get(position).toString()); |
| 73 | + FileOpsErrorCodes res = results.get(position); |
| 74 | + if(res==null) res = FileOpsErrorCodes.OK; |
| 75 | + result.setText(res.toString()); |
| 76 | + result.setTextColor(context.getResources().getColor(res == FileOpsErrorCodes.OK ? R.color.green : R.color.red)); |
| 77 | + |
| 78 | + return convertView; |
| 79 | + } |
| 80 | +} |
0 commit comments