in app/src/main/java/com/google/reviewit/UnifiedDiffFragment.java [242:350]
private void displayFiles(final Change change,
final Map<String, FileInfo> files,
final int startFileNumber,
final int totalFileCount) {
final Iterator<Map.Entry<String, FileInfo>> fileEntryIt =
files.entrySet().iterator();
diffView.setContent(new Iterator<ScrollWithHeadingsView.Content>() {
private int currentFileNumber = startFileNumber;
@Override
public boolean hasNext() {
return fileEntryIt.hasNext();
}
@Override
public ScrollWithHeadingsView.Content next() {
Map.Entry<String, FileInfo> fileEntry = fileEntryIt.next();
File f = new File(fileEntry.getKey());
return new ScrollWithHeadingsView.Content(
new ScrollWithHeadingsView.HeadingWithDetails(
getContext(), f.getName(),
new ScrollWithHeadingsView.RightAlignedHeadingDetails(
getContext().getString(R.string.file_count,
currentFileNumber++, totalFileCount)),
new ScrollWithHeadingsView.CenteredHeadingDetails(
FormatUtil.ensureSlash(f.getParent()))),
createContent(change, fileEntry.getKey(),
fileEntry.getValue()));
}
public View createContent(
final Change change, final String path, FileInfo file) {
final LinearLayout layout = new LinearLayout(getContext());
layout.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, widgetUtil.dpToPx(400)));
layout.setPadding(0, widgetUtil.dpToPx(30), 0, widgetUtil.dpToPx(30));
layout.setGravity(Gravity.CENTER_HORIZONTAL);
final ProgressBar p = new ProgressBar(getContext());
p.setLayoutParams(matchLayout());
p.setIndeterminate(true);
p.getIndeterminateDrawable().setColorFilter(
widgetUtil.color(R.color.progressReload),
android.graphics.PorterDuff.Mode.SRC_IN);
layout.addView(p);
if (file.binary != null && file.binary) {
// TODO
return layout;
}
LayoutUtil.addOneTimeOnGlobalLayoutListener(
p, new LayoutUtil.OneTimeOnGlobalLayoutListener() {
@Override
public void onFirstGlobalLayout() {
new AsyncTask<String, Void, DiffInfo>() {
@Override
protected DiffInfo doInBackground(String... paths) {
String path = paths[0];
try {
return change.diff(path);
} catch (RestApiException e) {
Log.e(TAG, "Failed to get diff of file " + path
+ " from change " + change.info._number, e);
return null;
}
}
protected void onPostExecute(final DiffInfo diff) {
layout.removeView(p);
layout.setLayoutParams(
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
layout.setPadding(0,
layout.getPaddingTop() - widgetUtil.dpToPx(20),
0,
layout.getPaddingBottom() - widgetUtil.dpToPx(20));
UnifiedDiffView unifiedDiffView = new UnifiedDiffView
(getContext(), diff);
layout.addView(unifiedDiffView);
LayoutUtil.addOneTimeOnGlobalLayoutListener(
unifiedDiffView,
new LayoutUtil.OneTimeOnGlobalLayoutListener() {
@Override
public void onFirstGlobalLayout() {
diffView.relayout();
}
});
unifiedDiffView.setOnSizeChangedListener(
new UnifiedDiffView.OnSizeChangedListener() {
@Override
public void onSizeChanged() {
diffView.relayout();
}
});
}
}.executeOnExecutor(getApp().getExecutor(), path);
}
});
return layout;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
});
}