Added contributors screen #336

Merged
merged 2 commits into from Jul 26, 2013
@@ -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" >
@@ -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>
@@ -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>
@@ -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"/>
@@ -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>
@@ -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">
@@ -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()));
+ }
+}
@@ -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);
+ }
+ }
+}
Oops, something went wrong.