/**
* Copyright (c) 2010 Perforce Software. All rights reserved.
*/
package com.perforce.p4scout;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import com.perforce.p4java.core.IFix;
import com.perforce.p4java.core.IJob;
import com.perforce.p4java.core.IJobSpec;
import com.perforce.p4java.core.IJobSpec.IJobSpecField;
/**
* @author NickPoole
*
*/
public class JobDetailAdapter extends BaseAdapter {
public enum ItemType {
FIX, OTHER;
}
protected IJob jobData;
protected IJobSpec jobSpec;
protected List<IFix> jobFixes;
protected boolean fixesError = false;
protected int fixes = 0;
protected Context context;
protected LayoutInflater inflater;
public JobDetailAdapter(Context context) {
this.context = context;
this.inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public JobDetailAdapter(Context context, IJob jobData, IJobSpec jobSpec) {
this.jobData = jobData;
this.jobSpec = jobSpec;
this.context = context;
this.inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void addFixes(List<IFix> jobFixes) {
if (this.jobFixes == null) {
this.jobFixes = jobFixes;
if (jobFixes.size() == 0) {
fixes = 2;
} else {
fixes = jobFixes.size() + 1;
}
}
}
public void addJobDetails(IJob jobData, IJobSpec jobSpec) {
if (this.jobData == null) {
this.jobData = jobData;
this.jobSpec = jobSpec;
}
}
@Override
public int getCount() {
if (jobData != null) {
return 1 + fixes;
}
return 0;
}
public IFix getFix(int position) {
if (jobFixes != null && jobFixes.size() > 0 && position > 0 && position - 1 != 0 &&
position - 1 < fixes) {
return jobFixes.get(position - 2);
}
return null;
}
/* (non-Javadoc)
* @see android.widget.Adapter#getItem(int)
*/
@Override
public ItemType getItem(int position) {
if (jobFixes != null && jobFixes.size() > 0 && position > 0 && position - 1 != 0 &&
position - 1 < fixes) {
return ItemType.FIX;
}
return ItemType.OTHER;
}
/* (non-Javadoc)
* @see android.widget.Adapter#getItemId(int)
*/
@Override
public long getItemId(int position) {
return position;
}
/**
* This is the method that draws each part of the Job details as a list.<br/>
* We change how we draw the items based on whether they are job fields, headers or fixes.
*
* @param position The position of the list item to be drawn
* @param convertView
* @param parent
*
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
*/
public View getView(int position, View convertView, ViewGroup parent) {
if (position == 0) {
// 0 will always be the job details
if (convertView == null || convertView.findViewById(R.id.llJobDetail) == null) {
convertView = inflater.inflate(R.layout.jobdetaillisting, parent, false);
}
((LinearLayout) convertView.findViewById(R.id.tlJobDetails))
.setVisibility(View.VISIBLE);
((TextView) convertView.findViewById(R.id.tvFixesHeader))
.setVisibility(View.GONE);
((TextView) convertView.findViewById(R.id.tvNoFixes))
.setVisibility(View.GONE);
((TextView) convertView.findViewById(R.id.tvTooManyFixes))
.setVisibility(View.GONE);
// We only need to populate the TableLayout if it hasn't already been populated
TableLayout tl = (TableLayout) convertView.findViewById(R.id.tlJobDetails);
if (tl.getChildCount() <= 0)
{
Map<String, Object> jobBits = jobData.getRawFields();
if (jobBits != null) {
for (IJobSpecField k : jobSpec.getFields()) {
if (k != null) {
TableRow row = new TableRow(context);
TextView keyText = new TextView(context);
keyText.setText(k.getName() + ":");
keyText.setTypeface(null, android.graphics.Typeface.BOLD);
row.addView(keyText);
row.setPadding(5, 3, 5, 0);
Object pair = jobBits.get(k.getName());
if (pair != null) {
if (k.getDataType().equals("text"))
{
tl.addView(row);
TableRow row2 = new TableRow(context);
if (pair instanceof java.lang.String) {
TextView valueText = new TextView(context);
valueText.setText((String) pair);
android.widget.TableRow.LayoutParams lparams =
new TableRow.LayoutParams();
lparams.span = 2;
valueText.setLayoutParams(lparams);
valueText.setPadding(5, 0, 5, 0);
row2.addView(valueText);
}
tl.addView(row2);
} else {
if (pair instanceof java.lang.String) {
TextView valueText = new TextView(context);
valueText.setText((String) pair);
valueText.setPadding(5, 3, 5, 0);
row.addView(valueText);
}
tl.addView(row);
}
} else if (true) { //(showEmptyFields) {
TextView valueText = new TextView(context);
valueText.setText(" ");
valueText.setPadding(5, 3, 5, 0);
row.addView(valueText);
tl.addView(row);
}
}
}
}
}
} else if (position - 1 < fixes) {
// This must be in the files section
if (position - 1 == 0) {
// Show the files header
if (convertView == null || convertView.findViewById(R.id.llJobDetail) == null) {
convertView = inflater.inflate(R.layout.jobdetaillisting, parent, false);
}
((LinearLayout) convertView.findViewById(R.id.tlJobDetails))
.setVisibility(View.GONE);
((TextView) convertView.findViewById(R.id.tvFixesHeader))
.setVisibility(View.VISIBLE);
((TextView) convertView.findViewById(R.id.tvNoFixes))
.setVisibility(View.GONE);
((TextView) convertView.findViewById(R.id.tvTooManyFixes))
.setVisibility(View.GONE);
} else if (fixesError == true) {
// Show the too many fixes message
if (convertView == null || convertView.findViewById(R.id.llJobDetail) == null) {
convertView = inflater.inflate(R.layout.jobdetaillisting, parent, false);
}
((LinearLayout) convertView.findViewById(R.id.tlJobDetails))
.setVisibility(View.GONE);
((TextView) convertView.findViewById(R.id.tvFixesHeader))
.setVisibility(View.GONE);
((TextView) convertView.findViewById(R.id.tvNoFixes))
.setVisibility(View.GONE);
((TextView) convertView.findViewById(R.id.tvTooManyFixes))
.setVisibility(View.VISIBLE);
} else if (jobFixes.size() == 0) {
// Show the "no associated files" placeholder
if (convertView == null || convertView.findViewById(R.id.llJobDetail) == null) {
convertView = inflater.inflate(R.layout.jobdetaillisting, parent, false);
}
((LinearLayout) convertView.findViewById(R.id.tlJobDetails))
.setVisibility(View.GONE);
((TextView) convertView.findViewById(R.id.tvFixesHeader))
.setVisibility(View.GONE);
((TextView) convertView.findViewById(R.id.tvNoFixes))
.setVisibility(View.VISIBLE);
((TextView) convertView.findViewById(R.id.tvTooManyFixes))
.setVisibility(View.GONE);
} else {
// Show the fix listing
if (convertView == null || convertView.findViewById(R.id.tvChangeNum) == null) {
convertView = inflater.inflate(R.layout.fixlisting, parent, false);
}
((TextView) convertView.findViewById(R.id.tvChangeNum))
.setText(Integer.toString(jobFixes.get(position - 2).getChangelistId()));
((TextView) convertView.findViewById(R.id.tvFixTime))
.setText(jobFixes.get(position - 2).getDate().toLocaleString());
((TextView) convertView.findViewById(R.id.tvFixStatus))
.setText(jobFixes.get(position - 2).getStatus());
((TextView) convertView.findViewById(R.id.tvFixUser))
.setText(jobFixes.get(position - 2).getUserName());
}
}
return convertView;
}
public void tooManyFixes() {
fixesError = true;
fixes = 2;
jobFixes = null;
}
}
# |
Change |
User |
Description |
Committed |
|
#1
|
8980 |
Matt Attaway |
Add source code for both the Android and iOS versions of P4Scout. |
|
|