Skip to content

Commit

Permalink
Display commits as headers above line differences
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsawicki committed Jul 20, 2012
1 parent ec962b3 commit 5b0056c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 6 deletions.
28 changes: 26 additions & 2 deletions app/res/layout/commit_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,35 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/ListItem" >

<ImageView
android:id="@+id/iv_avatar"
style="@style/AvatarLarge"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:contentDescription="@string/avatar" />

<TextView
android:id="@+id/tv_commit_id"
style="@style/ListSubtitleText"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/iv_avatar"
android:singleLine="true" />

<TextView
android:id="@+id/tv_commit_message"
style="@style/ListTitleText"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_width="match_parent"
android:layout_alignLeft="@id/tv_commit_id"
android:layout_below="@id/tv_commit_id"
android:singleLine="true" />

<TextView
android:id="@+id/tv_commit_author"
style="@style/ListSubtitleText"
android:layout_alignLeft="@id/tv_commit_message"
android:layout_below="@id/tv_commit_message"
android:singleLine="true" />

</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ public boolean removeHeader(View v) {
return removed;
}

/**
* Remove all headers
*
* @return true if headers were removed, false otherwise
*/
public boolean clearHeaders() {
boolean removed = false;
for (FixedViewInfo info : headers)
removed = super.removeHeader(info.view) || removed;
if (removed)
wrapped.notifyDataSetChanged();
return removed;
}

/**
* Remove all footers
*
* @return true if headers were removed, false otherwise
*/
public boolean clearFooters() {
boolean removed = false;
for (FixedViewInfo info : footers)
removed = super.removeFooter(info.view) || removed;
if (removed)
wrapped.notifyDataSetChanged();
return removed;
}

@Override
public boolean removeFooter(View v) {
boolean removed = super.removeFooter(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,28 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.github.mobile.R.id;
import com.github.mobile.core.commit.CommitCompareTask;
import com.github.mobile.ui.DialogFragment;
import com.github.mobile.ui.HeaderFooterListAdapter;
import com.github.mobile.ui.StyledText;
import com.github.mobile.util.AvatarLoader;
import com.github.mobile.util.ViewUtils;
import com.google.inject.Inject;
import com.viewpagerindicator.R.layout;

import java.util.Collections;
import java.util.List;

import org.eclipse.egit.github.core.Commit;
import org.eclipse.egit.github.core.CommitFile;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryCommit;
import org.eclipse.egit.github.core.RepositoryCommitCompare;

import roboguice.inject.InjectExtra;
Expand Down Expand Up @@ -64,7 +71,8 @@ public class CommitCompareListFragment extends DialogFragment {
@InjectExtra(EXTRA_HEAD)
private String head;

private RepositoryCommitCompare compare;
@Inject
private AvatarLoader avatars;

private HeaderFooterListAdapter<CommitFileListAdapter> adapter;

Expand Down Expand Up @@ -95,17 +103,41 @@ protected void onSuccess(RepositoryCommitCompare compare)
throws Exception {
super.onSuccess(compare);

CommitCompareListFragment.this.compare = compare;
updateList();
updateList(compare);
}

}.execute();
}

private void updateList() {
private void updateList(RepositoryCommitCompare compare) {
if (!isUsable())
return;

ViewUtils.setGone(progress, true);
ViewUtils.setGone(list, false);

LayoutInflater inflater = getActivity().getLayoutInflater();
adapter.clearHeaders();
List<RepositoryCommit> commits = compare.getCommits();
if (commits != null && !commits.isEmpty())
for (RepositoryCommit commit : commits) {
View header = inflater.inflate(layout.commit_item, null);
avatars.bind((ImageView) header.findViewById(id.iv_avatar),
commit.getAuthor());
Commit rawCommit = commit.getCommit();
((TextView) header.findViewById(id.tv_commit_id))
.setText(commit.getSha());
StyledText author = new StyledText();
author.bold(commit.getAuthor().getLogin());
author.append(' ');
author.append(rawCommit.getAuthor().getDate());
((TextView) header.findViewById(id.tv_commit_author))
.setText(author);
((TextView) header.findViewById(id.tv_commit_message))
.setText(rawCommit.getMessage());
adapter.addHeader(header, commit, true);
}

List<CommitFile> files = compare.getFiles();
if (files != null && !files.isEmpty())
adapter.getWrappedAdapter().setItems(
Expand Down

0 comments on commit 5b0056c

Please sign in to comment.