Permalink
Browse files

Add contributors screen

  • Loading branch information...
1 parent bd47425 commit 719ebed483fff3ee0edb0ca64e7b8231dc02f582 @atermenji committed Mar 31, 2013
View
10 app/AndroidManifest.xml
@@ -186,6 +186,16 @@
android:value=".ui.issue.IssueSearchActivity" />
</activity>
<activity
+ android:name=".ui.repo.RepositoryContributorsActivity"
+ android:configChanges="orientation|keyboardHidden|screenSize"
+ android:hardwareAccelerated="true" >
+ <intent-filter>
+ <action android:name="com.github.mobile.repo.contributors.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+ <activity
android:name=".ui.user.UserViewActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:hardwareAccelerated="true" >
View
49 app/res/layout/contributor_item.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2013 GitHub Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/ListItemTwoLines"
+ android:gravity="center_vertical"
+ android:orientation="horizontal" >
+
+ <ImageView
+ android:id="@+id/iv_avatar"
+ style="@style/AvatarXLarge"
+ android:contentDescription="@string/avatar" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/tv_login"
+ style="@style/ListTitleText"
+ android:paddingLeft="10dp"
+ android:paddingBottom="0dp"
+ android:singleLine="true"
+ android:textStyle="normal" />
+
+ <TextView
+ android:id="@+id/tv_contributions"
+ style="@style/ListSubtitleText"
+ android:paddingLeft="10dp"
+ android:singleLine="true"
+ android:textStyle="normal" />
+
+ </LinearLayout>
+
+</LinearLayout>
View
35 app/res/layout/repo_contributors.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2013 GitHub Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <View
+ android:id="@+id/v_header_separator"
+ style="@style/HeaderSeparator"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"/>
+
+ <fragment
+ android:id="@android:id/list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_alignParentLeft="true"
+ android:layout_below="@id/v_header_separator"
+ class="com.github.mobile.ui.repo.RepositoryContributorsFragment"/>
+
+</RelativeLayout>
View
4 app/res/menu/repository.xml
@@ -21,6 +21,10 @@
android:showAsAction="never"
android:title="@string/star"/>
<item
+ android:id="@+id/m_contributors"
+ android:showAsAction="never"
+ android:title="@string/contributors"/>
+ <item
android:id="@+id/m_share"
android:showAsAction="never"
android:title="@string/share"/>
View
4 app/res/values/strings.xml
@@ -21,6 +21,7 @@
<string name="error_issues_load">Loading issues failed</string>
<string name="error_repos_load">Loading repositories failed</string>
<string name="error_repo_load">Loading repository failed</string>
+ <string name="error_contributors_load">Loading contributors failed</string>
<string name="error_gist_load">Loading Gist failed</string>
<string name="error_news_load">Loading news failed</string>
<string name="error_followers_load">Loading followers failed</string>
@@ -73,6 +74,7 @@
<!-- Empty messages -->
<string name="no_bookmarks">No Bookmarks</string>
<string name="no_repositories">No Repositories</string>
+ <string name="no_contributors">No contributors</string>
<string name="no_issues">No Issues</string>
<string name="no_gists">No Gists</string>
<string name="no_people">No People</string>
@@ -131,6 +133,7 @@
<string name="comment_hint">Enter a comment</string>
<string name="show_more">Show More…</string>
<string name="repositories">Repositories</string>
+ <string name="contributors">Contributors</string>
<string name="issues_title">Issues</string>
<string name="edit_labels">Edit Labels</string>
<string name="milestone_prefix">Milestone:</string>
@@ -238,6 +241,7 @@
<string name="unstarring_repository">Unstarring…</string>
<string name="navigate_to">Navigate to…</string>
<string name="navigate_to_user">Navigate to %s</string>
+ <string name="contributions">%d commits</string>
<!-- Tab titles, should be as short as possible -->
<string name="tab_repositories">repositories</string>
View
10 app/res/values/styles.xml
@@ -26,6 +26,11 @@
<item name="android:layout_height">28dp</item>
</style>
+ <style name="AvatarXLarge">
+ <item name="android:layout_width">40dp</item>
+ <item name="android:layout_height">40dp</item>
+ </style>
+
<style name="AvatarLarge">
<item name="android:layout_width">32dp</item>
<item name="android:layout_height">32dp</item>
@@ -178,6 +183,11 @@
<item name="android:background">@drawable/list_item_background</item>
</style>
+ <style name="ListItemTwoLines" parent="ListItem">
+ <item name="android:paddingTop">5dp</item>
+ <item name="android:paddingBottom">5dp</item>
+ </style>
+
<style name="HeaderListItem" parent="ListItem"></style>
<style name="CommentListItem" parent="ListItem">
View
70 app/src/main/java/com/github/mobile/ui/repo/ContributorListAdapter.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2013 GitHub Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.mobile.ui.repo;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+
+import com.github.kevinsawicki.wishlist.SingleTypeAdapter;
+import com.github.mobile.R.layout;
+import com.github.mobile.R.string;
+import com.github.mobile.R.id;
+import com.github.mobile.util.AvatarLoader;
+
+import org.eclipse.egit.github.core.Contributor;
+
+/**
+ * List adapter for a list of contributors
+ */
+public class ContributorListAdapter extends SingleTypeAdapter<Contributor> {
+
+ private final Context context;
+
+ private final AvatarLoader avatars;
+
+ /**
+ * Create contributor list adapter
+ *
+ * @param context
+ * @param elements
+ * @param avatars
+ */
+ public ContributorListAdapter(final Context context,
+ final Contributor[] elements, final AvatarLoader avatars) {
+ super(LayoutInflater.from(context), layout.contributor_item);
+
+ this.context = context.getApplicationContext();
+ this.avatars = avatars;
+ setItems(elements);
+ }
+
+ @Override
+ public long getItemId(final int position) {
+ return getItem(position).getId();
+ }
+
+ @Override
+ protected int[] getChildViewIds() {
+ return new int[] { id.iv_avatar, id.tv_login, id.tv_contributions };
+ }
+
+ @Override
+ protected void update(int position, Contributor contributor) {
+ avatars.bind(imageView(0), contributor);
+ setText(1, contributor.getLogin());
+ setText(2, context.getString(string.contributions, contributor.getContributions()));
+ }
+}
View
85 app/src/main/java/com/github/mobile/ui/repo/RepositoryContributorsActivity.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2013 GitHub Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.mobile.ui.repo;
+
+import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
+import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
+import static com.github.mobile.Intents.EXTRA_REPOSITORY;
+import android.content.Intent;
+import android.os.Bundle;
+
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.view.MenuItem;
+import com.github.mobile.Intents;
+import com.github.mobile.R.string;
+import com.github.mobile.R.layout;
+import com.github.mobile.ui.DialogFragmentActivity;
+import com.github.mobile.util.AvatarLoader;
+import com.google.inject.Inject;
+
+import org.eclipse.egit.github.core.Repository;
+import org.eclipse.egit.github.core.User;
+
+/**
+ * Activity to view repository contributors
+ */
+public class RepositoryContributorsActivity extends DialogFragmentActivity {
+
+ /**
+ * Create intent for this activity
+ *
+ * @param repository
+ * @return intent
+ */
+ public static Intent createIntent(Repository repository) {
+ return new Intents.Builder("repo.contributors.VIEW").repo(repository).toIntent();
+ }
+
+ private Repository repository;
+
+ @Inject
+ private AvatarLoader avatars;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(layout.repo_contributors);
+
+ repository = getSerializableExtra(EXTRA_REPOSITORY);
+
+ ActionBar actionBar = getSupportActionBar();
+ actionBar.setTitle(repository.getName());
+ actionBar.setSubtitle(string.contributors);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+
+ User owner = repository.getOwner();
+ avatars.bind(getSupportActionBar(), owner);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ Intent intent = RepositoryViewActivity.createIntent(repository);
+ intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
+ startActivity(intent);
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+}
View
90 app/src/main/java/com/github/mobile/ui/repo/RepositoryContributorsFragment.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2013 GitHub Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.mobile.ui.repo;
+
+import static com.github.mobile.Intents.EXTRA_REPOSITORY;
+import android.app.Activity;
+import android.os.Bundle;
+import android.support.v4.content.Loader;
+
+import com.github.kevinsawicki.wishlist.SingleTypeAdapter;
+import com.github.mobile.R.string;
+import com.github.mobile.ThrowableLoader;
+import com.github.mobile.ui.ItemListFragment;
+import com.github.mobile.util.AvatarLoader;
+import com.google.inject.Inject;
+
+import java.util.List;
+
+import org.eclipse.egit.github.core.Contributor;
+import org.eclipse.egit.github.core.Repository;
+import org.eclipse.egit.github.core.service.RepositoryService;
+
+/**
+ * Fragment to display a list of contributors for a specific repository
+ */
+public class RepositoryContributorsFragment extends ItemListFragment<Contributor> {
+
+ /**
+ * Avatar loader
+ */
+ @Inject
+ protected AvatarLoader avatars;
+
+ /**
+ * Repository service
+ */
+ @Inject
+ protected RepositoryService service;
+
+ private Repository repo;
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+
+ repo = getSerializableExtra(EXTRA_REPOSITORY);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ setEmptyText(string.no_contributors);
+ }
+
+ @Override
+ public Loader<List<Contributor>> onCreateLoader(int id, Bundle args) {
+ return new ThrowableLoader<List<Contributor>>(getActivity(), items) {
+
+ @Override
+ public List<Contributor> loadData() throws Exception {
+ return service.getContributors(repo, false);
+ }
+ };
+ }
+
+ @Override
+ protected SingleTypeAdapter<Contributor> createAdapter(List<Contributor> items) {
+ return new ContributorListAdapter(getActivity(),
+ items.toArray(new Contributor[items.size()]), avatars);
+ }
+
+ @Override
+ protected int getErrorMessage(Exception exception) {
+ return string.error_contributors_load;
+ }
+}
View
3 app/src/main/java/com/github/mobile/ui/repo/RepositoryViewActivity.java
@@ -180,6 +180,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
case id.m_refresh:
checkStarredRepositoryStatus();
return super.onOptionsItemSelected(item);
+ case id.m_contributors:
+ startActivity(RepositoryContributorsActivity.createIntent(repository));
+ return true;
case android.R.id.home:
finish();
Intent intent = UserViewActivity.createIntent(repository.getOwner());
View
29 app/src/main/java/com/github/mobile/util/AvatarLoader.java
@@ -45,6 +45,7 @@
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.egit.github.core.CommitUser;
+import org.eclipse.egit.github.core.Contributor;
import org.eclipse.egit.github.core.User;
import roboguice.util.RoboAsyncTask;
@@ -374,6 +375,34 @@ public AvatarLoader bind(final ImageView view, final CommitUser user) {
return this;
}
+ /**
+ * Bind view to image at URL
+ *
+ * @param view
+ * @param contributor
+ * @return this helper
+ */
+ public AvatarLoader bind(final ImageView view, final Contributor contributor) {
+ if (contributor == null)
+ return setImage(loadingAvatar, view);
+
+ final String avatarUrl = contributor.getAvatarUrl();
+
+ if (TextUtils.isEmpty(avatarUrl))
+ return setImage(loadingAvatar, view);
+
+ final String contributorId = contributor.getLogin();
+
+ BitmapDrawable loadedImage = loaded.get(contributorId);
+ if (loadedImage != null)
+ return setImage(loadedImage, view);
+
+ setImage(loadingAvatar, view, contributorId);
+ fetchAvatarTask(avatarUrl, contributorId, view).execute();
+
+ return this;
+ }
+
private FetchAvatarTask fetchAvatarTask(final String avatarUrl,
final String userId, final ImageView view) {
return new FetchAvatarTask(context) {

0 comments on commit 719ebed

Please sign in to comment.