Skip to content

Commit e314771

Browse files
committed
Add watcher and fork counts to repository lists
1 parent a820d57 commit e314771

8 files changed

Lines changed: 145 additions & 20 deletions

File tree

app/res/layout/repo_item.xml

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,28 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
-->
17-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
17+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
1818
android:layout_width="match_parent"
1919
android:layout_height="match_parent"
20-
android:orientation="horizontal"
21-
android:padding="10dp" >
20+
android:gravity="center_vertical"
21+
android:paddingBottom="5dp"
22+
android:paddingLeft="10dp"
23+
android:paddingRight="10dp"
24+
android:paddingTop="5dp" >
2225

2326
<TextView
2427
android:id="@+id/tv_repo_icon"
2528
style="@style/PrimaryIcon"
26-
android:paddingRight="10dp" />
29+
android:layout_alignParentLeft="true"
30+
android:layout_alignParentTop="true" />
2731

2832
<LinearLayout
2933
android:layout_width="match_parent"
3034
android:layout_height="match_parent"
31-
android:gravity="center_vertical"
32-
android:orientation="vertical" >
35+
android:layout_alignParentTop="true"
36+
android:layout_toRightOf="@id/tv_repo_icon"
37+
android:orientation="vertical"
38+
android:paddingLeft="10dp" >
3339

3440
<LinearLayout
3541
android:layout_width="match_parent"
@@ -61,9 +67,46 @@
6167
android:id="@+id/tv_repo_description"
6268
android:layout_width="match_parent"
6369
android:layout_height="wrap_content"
70+
android:layout_gravity="center_vertical"
6471
android:singleLine="true"
6572
android:textAppearance="?android:attr/textAppearanceSmall"
6673
android:textColor="@color/item_text_color_light" />
74+
75+
<LinearLayout
76+
android:layout_width="match_parent"
77+
android:layout_height="wrap_content"
78+
android:gravity="center_vertical"
79+
android:orientation="horizontal" >
80+
81+
<TextView
82+
android:id="@+id/tv_watchers_icon"
83+
style="@style/ListIcon"
84+
android:text="\uf04E" />
85+
86+
<TextView
87+
android:id="@+id/tv_watchers"
88+
android:layout_width="wrap_content"
89+
android:layout_height="wrap_content"
90+
android:paddingLeft="5dp"
91+
android:paddingRight="10dp"
92+
android:singleLine="true"
93+
android:textAppearance="?android:attr/textAppearanceSmall"
94+
android:textColor="@color/item_text_color_light" />
95+
96+
<TextView
97+
android:id="@+id/tv_forks_icon"
98+
style="@style/ListIcon"
99+
android:text="\uf020" />
100+
101+
<TextView
102+
android:id="@+id/tv_forks"
103+
android:layout_width="wrap_content"
104+
android:layout_height="wrap_content"
105+
android:paddingLeft="3dp"
106+
android:singleLine="true"
107+
android:textAppearance="?android:attr/textAppearanceSmall"
108+
android:textColor="@color/item_text_color_light" />
109+
</LinearLayout>
67110
</LinearLayout>
68111

69-
</LinearLayout>
112+
</RelativeLayout>

app/res/layout/user_repo_item.xml

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,28 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
-->
17-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
17+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
1818
android:layout_width="match_parent"
1919
android:layout_height="match_parent"
20-
android:orientation="horizontal"
21-
android:padding="10dp" >
20+
android:gravity="center_vertical"
21+
android:paddingBottom="5dp"
22+
android:paddingLeft="10dp"
23+
android:paddingRight="10dp"
24+
android:paddingTop="5dp" >
2225

2326
<TextView
2427
android:id="@+id/tv_repo_icon"
2528
style="@style/PrimaryIcon"
26-
android:paddingRight="10dp" />
29+
android:layout_alignParentLeft="true"
30+
android:layout_alignParentTop="true" />
2731

2832
<LinearLayout
2933
android:layout_width="match_parent"
3034
android:layout_height="match_parent"
31-
android:gravity="center_vertical"
32-
android:orientation="vertical" >
35+
android:layout_alignParentTop="true"
36+
android:layout_toRightOf="@id/tv_repo_icon"
37+
android:orientation="vertical"
38+
android:paddingLeft="10dp" >
3339

3440
<TextView
3541
android:id="@+id/tv_repo_name"
@@ -48,6 +54,42 @@
4854
android:singleLine="true"
4955
android:textAppearance="?android:attr/textAppearanceSmall"
5056
android:textColor="@color/item_text_color_light" />
57+
58+
<LinearLayout
59+
android:layout_width="match_parent"
60+
android:layout_height="wrap_content"
61+
android:gravity="center_vertical"
62+
android:orientation="horizontal" >
63+
64+
<TextView
65+
android:id="@+id/tv_watchers_icon"
66+
style="@style/ListIcon"
67+
android:text="\uf04E" />
68+
69+
<TextView
70+
android:id="@+id/tv_watchers"
71+
android:layout_width="wrap_content"
72+
android:layout_height="wrap_content"
73+
android:paddingLeft="5dp"
74+
android:paddingRight="10dp"
75+
android:singleLine="true"
76+
android:textAppearance="?android:attr/textAppearanceSmall"
77+
android:textColor="@color/item_text_color_light" />
78+
79+
<TextView
80+
android:id="@+id/tv_forks_icon"
81+
style="@style/ListIcon"
82+
android:text="\uf020" />
83+
84+
<TextView
85+
android:id="@+id/tv_forks"
86+
android:layout_width="wrap_content"
87+
android:layout_height="wrap_content"
88+
android:paddingLeft="3dp"
89+
android:singleLine="true"
90+
android:textAppearance="?android:attr/textAppearanceSmall"
91+
android:textColor="@color/item_text_color_light" />
92+
</LinearLayout>
5193
</LinearLayout>
5294

53-
</LinearLayout>
95+
</RelativeLayout>

app/src/main/java/com/github/mobile/persistence/CacheHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class CacheHelper extends SQLiteOpenHelper {
2929
/**
3030
* Version constant to increment when the database should be rebuilt
3131
*/
32-
private static final int VERSION = 3;
32+
private static final int VERSION = 4;
3333

3434
/**
3535
* Name of database file
@@ -48,7 +48,7 @@ public CacheHelper(final Context context) {
4848
public void onCreate(final SQLiteDatabase db) {
4949
db.execSQL("CREATE TABLE orgs (id INTEGER PRIMARY KEY);");
5050
db.execSQL("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, avatarurl TEXT);");
51-
db.execSQL("CREATE TABLE repos (id INTEGER PRIMARY KEY, orgId INTEGER, name TEXT, ownerId INTEGER, private INTEGER, fork INTEGER, description TEXT);");
51+
db.execSQL("CREATE TABLE repos (id INTEGER PRIMARY KEY, orgId INTEGER, name TEXT, ownerId INTEGER, private INTEGER, fork INTEGER, description TEXT, forks INTEGER, watchers INTEGER);");
5252
}
5353

5454
@Override

app/src/main/java/com/github/mobile/persistence/OrganizationRepositories.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ public OrganizationRepositories(@Assisted User orgs, RepositoryService repos,
7676
public Cursor getCursor(SQLiteDatabase readableDatabase) {
7777
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
7878
builder.setTables("repos JOIN users ON (repos.ownerId = users.id)");
79-
return builder.query(readableDatabase, new String[] { "repos.id, repos.name", "users.id", "users.name",
80-
"users.avatarurl", "repos.private", "repos.fork", "repos.description" }, "repos.orgId=?",
79+
return builder.query(readableDatabase,
80+
new String[] { "repos.id, repos.name", "users.id", "users.name", "users.avatarurl", "repos.private",
81+
"repos.fork", "repos.description", "repos.forks", "repos.watchers" }, "repos.orgId=?",
8182
new String[] { Integer.toString(org.getId()) }, null, null, null);
8283
}
8384

@@ -96,6 +97,8 @@ public Repository loadFrom(Cursor cursor) {
9697
repo.setPrivate(cursor.getInt(5) == 1);
9798
repo.setFork(cursor.getInt(6) == 1);
9899
repo.setDescription(cursor.getString(7));
100+
repo.setForks(cursor.getInt(8));
101+
repo.setWatchers(cursor.getInt(9));
99102

100103
return repo;
101104
}
@@ -105,7 +108,7 @@ public void store(SQLiteDatabase db, List<Repository> repos) {
105108
db.delete("repos", "orgId=?", new String[] { Integer.toString(org.getId()) });
106109
for (Repository repo : repos) {
107110
User owner = repo.getOwner();
108-
ContentValues values = new ContentValues(7);
111+
ContentValues values = new ContentValues(9);
109112

110113
values.put("id", repo.getId());
111114
values.put("name", repo.getName());
@@ -114,6 +117,8 @@ public void store(SQLiteDatabase db, List<Repository> repos) {
114117
values.put("private", repo.isPrivate() ? 1 : 0);
115118
values.put("fork", repo.isFork() ? 1 : 0);
116119
values.put("description", repo.getDescription());
120+
values.put("forks", repo.getForks());
121+
values.put("watchers", repo.getWatchers());
117122
db.replace("repos", null, values);
118123

119124
values.clear();

app/src/main/java/com/github/mobile/ui/repo/RepositoryItemView.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,30 @@ public class RepositoryItemView extends ItemView {
4242
*/
4343
public final TextView repoDescription;
4444

45+
/**
46+
* Number of watchers
47+
*/
48+
public final TextView watchers;
49+
50+
/**
51+
* Number of forks
52+
*/
53+
public final TextView forks;
54+
4555
/**
4656
* @param view
4757
*/
4858
public RepositoryItemView(final View view) {
4959
super(view);
5060

5161
repoIcon = (TextView) view.findViewById(id.tv_repo_icon);
52-
TypefaceUtils.setOcticons(repoIcon);
5362
repoName = (TextView) view.findViewById(id.tv_repo_name);
5463
repoDescription = (TextView) view.findViewById(id.tv_repo_description);
64+
65+
TypefaceUtils.setOcticons(repoIcon, (TextView) view.findViewById(id.tv_forks_icon),
66+
(TextView) view.findViewById(id.tv_watchers_icon));
67+
68+
watchers = (TextView) view.findViewById(id.tv_watchers);
69+
forks = (TextView) view.findViewById(id.tv_forks);
5570
}
5671
}

app/src/main/java/com/github/mobile/ui/repo/RepositoryListAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.github.mobile.ui.ItemListAdapter;
2828
import com.viewpagerindicator.R.layout;
2929

30+
import java.text.NumberFormat;
3031
import java.util.concurrent.atomic.AtomicReference;
3132

3233
import org.eclipse.egit.github.core.Repository;
@@ -37,6 +38,8 @@
3738
*/
3839
public class RepositoryListAdapter extends ItemListAdapter<Repository, RecentRepositoryItemView> {
3940

41+
private static final NumberFormat FORMAT = NumberFormat.getIntegerInstance();
42+
4043
private final AtomicReference<User> account;
4144

4245
private final AtomicReference<RecentRepositories> recent;
@@ -90,6 +93,9 @@ else if (repository.isFork())
9093
view.repoDescription.setVisibility(VISIBLE);
9194
} else
9295
view.repoDescription.setVisibility(GONE);
96+
97+
view.watchers.setText(FORMAT.format(repository.getWatchers()));
98+
view.forks.setText(FORMAT.format(repository.getForks()));
9399
}
94100

95101
@Override

app/src/main/java/com/github/mobile/ui/repo/SearchRepositoryListAdapter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@
2727
import com.github.mobile.ui.ItemListAdapter;
2828
import com.viewpagerindicator.R.layout;
2929

30+
import java.text.NumberFormat;
31+
3032
import org.eclipse.egit.github.core.SearchRepository;
3133

3234
/**
3335
* Adapter for a list of searched for repositories
3436
*/
3537
public class SearchRepositoryListAdapter extends ItemListAdapter<SearchRepository, RepositoryItemView> {
3638

39+
private static final NumberFormat FORMAT = NumberFormat.getIntegerInstance();
40+
3741
/**
3842
* Create list adapter for searched for repositories
3943
*
@@ -71,6 +75,9 @@ else if (repository.isFork())
7175
view.repoDescription.setVisibility(VISIBLE);
7276
} else
7377
view.repoDescription.setVisibility(GONE);
78+
79+
view.watchers.setText(FORMAT.format(repository.getWatchers()));
80+
view.forks.setText(FORMAT.format(repository.getForks()));
7481
}
7582

7683
@Override

app/src/main/java/com/github/mobile/ui/repo/UserRepositoryListAdapter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.github.mobile.ui.ItemListAdapter;
2828
import com.viewpagerindicator.R.layout;
2929

30+
import java.text.NumberFormat;
31+
3032
import org.eclipse.egit.github.core.Repository;
3133
import org.eclipse.egit.github.core.User;
3234

@@ -35,6 +37,8 @@
3537
*/
3638
public class UserRepositoryListAdapter extends ItemListAdapter<Repository, RepositoryItemView> {
3739

40+
private static final NumberFormat FORMAT = NumberFormat.getIntegerInstance();
41+
3842
private final String login;
3943

4044
/**
@@ -78,6 +82,9 @@ else if (repository.isFork())
7882
view.repoDescription.setVisibility(VISIBLE);
7983
} else
8084
view.repoDescription.setVisibility(GONE);
85+
86+
view.watchers.setText(FORMAT.format(repository.getWatchers()));
87+
view.forks.setText(FORMAT.format(repository.getForks()));
8188
}
8289

8390
@Override

0 commit comments

Comments
 (0)