Skip to content

Commit 2ff66e4

Browse files
committed
Show icons for public and private repository mirrors
Requires upgrading the repository database to track the mirror URL from the Repository model class.
1 parent a3ef0b6 commit 2ff66e4

7 files changed

Lines changed: 37 additions & 14 deletions

File tree

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 = 7;
32+
private static final int VERSION = 8;
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, repoId INTEGER, orgId INTEGER, name TEXT, ownerId INTEGER, private INTEGER, fork INTEGER, description TEXT, forks INTEGER, watchers INTEGER, language TEXT, hasIssues INTEGER);");
51+
db.execSQL("CREATE TABLE repos (id INTEGER PRIMARY KEY, repoId INTEGER, orgId INTEGER, name TEXT, ownerId INTEGER, private INTEGER, fork INTEGER, description TEXT, forks INTEGER, watchers INTEGER, language TEXT, hasIssues INTEGER, mirrorUrl TEXT);");
5252
}
5353

5454
@Override

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public Cursor getCursor(SQLiteDatabase readableDatabase) {
9191
"repos.repoId, repos.name", "users.id", "users.name",
9292
"users.avatarurl", "repos.private", "repos.fork",
9393
"repos.description", "repos.forks", "repos.watchers",
94-
"repos.language", "repos.hasIssues" }, "repos.orgId=?",
94+
"repos.language", "repos.hasIssues", "repos.mirrorUrl" },
95+
"repos.orgId=?",
9596
new String[] { Integer.toString(org.getId()) }, null, null,
9697
null);
9798
}
@@ -115,6 +116,7 @@ public Repository loadFrom(Cursor cursor) {
115116
repo.setWatchers(cursor.getInt(9));
116117
repo.setLanguage(cursor.getString(10));
117118
repo.setHasIssues(cursor.getInt(11) == 1);
119+
repo.setMirrorUrl(cursor.getString(12));
118120

119121
return repo;
120122
}
@@ -125,7 +127,7 @@ public void store(SQLiteDatabase db, List<Repository> repos) {
125127
new String[] { Integer.toString(org.getId()) });
126128
for (Repository repo : repos) {
127129
User owner = repo.getOwner();
128-
ContentValues values = new ContentValues(11);
130+
ContentValues values = new ContentValues(12);
129131

130132
values.put("repoId", repo.getId());
131133
values.put("name", repo.getName());
@@ -138,6 +140,7 @@ public void store(SQLiteDatabase db, List<Repository> repos) {
138140
values.put("watchers", repo.getWatchers());
139141
values.put("language", repo.getLanguage());
140142
values.put("hasIssues", repo.isHasIssues() ? 1 : 0);
143+
values.put("mirrorUrl", repo.getMirrorUrl());
141144
db.replace("repos", null, values);
142145

143146
values.clear();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected void update(final int position,
134134
updateDetails(view, repository.getDescription(),
135135
repository.getLanguage(), repository.getWatchers(),
136136
repository.getForks(), repository.isPrivate(),
137-
repository.isFork());
137+
repository.isFork(), repository.getMirrorUrl());
138138
}
139139

140140
@Override

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import static android.view.View.GONE;
1919
import static android.view.View.VISIBLE;
2020
import static com.github.mobile.util.TypefaceUtils.ICON_FORK;
21+
import static com.github.mobile.util.TypefaceUtils.ICON_MIRROR_PRIVATE;
22+
import static com.github.mobile.util.TypefaceUtils.ICON_MIRROR_PUBLIC;
2123
import static com.github.mobile.util.TypefaceUtils.ICON_PRIVATE;
2224
import static com.github.mobile.util.TypefaceUtils.ICON_PUBLIC;
2325
import android.text.TextUtils;
@@ -77,17 +79,25 @@ public RepositoryListAdapter(int viewId, LayoutInflater inflater) {
7779
* @param forks
7880
* @param isPrivate
7981
* @param isFork
82+
* @param mirrorUrl
8083
*/
8184
protected void updateDetails(final RepositoryItemView view,
8285
final String description, final String language,
8386
final int watchers, final int forks, final boolean isPrivate,
84-
final boolean isFork) {
85-
if (isPrivate)
86-
view.repoIcon.setText(Character.toString(ICON_PRIVATE));
87-
else if (isFork)
88-
view.repoIcon.setText(Character.toString(ICON_FORK));
89-
else
90-
view.repoIcon.setText(Character.toString(ICON_PUBLIC));
87+
final boolean isFork, final String mirrorUrl) {
88+
if (TextUtils.isEmpty(mirrorUrl))
89+
if (isPrivate)
90+
view.repoIcon.setText(Character.toString(ICON_PRIVATE));
91+
else if (isFork)
92+
view.repoIcon.setText(Character.toString(ICON_FORK));
93+
else
94+
view.repoIcon.setText(Character.toString(ICON_PUBLIC));
95+
else {
96+
if (isPrivate)
97+
view.repoIcon.setText(Character.toString(ICON_MIRROR_PRIVATE));
98+
else
99+
view.repoIcon.setText(Character.toString(ICON_MIRROR_PUBLIC));
100+
}
91101

92102
if (!TextUtils.isEmpty(description)) {
93103
view.repoDescription.setText(description);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected void update(final int position, final RepositoryItemView view,
6262
updateDetails(view, repository.getDescription(),
6363
repository.getLanguage(), repository.getWatchers(),
6464
repository.getForks(), repository.isPrivate(),
65-
repository.isFork());
65+
repository.isFork(), null);
6666
}
6767

6868
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected void update(final int position, final RepositoryItemView view,
7373
updateDetails(view, repository.getDescription(),
7474
repository.getLanguage(), repository.getWatchers(),
7575
repository.getForks(), repository.isPrivate(),
76-
repository.isFork());
76+
repository.isFork(), repository.getMirrorUrl());
7777
}
7878

7979
@Override

app/src/main/java/com/github/mobile/util/TypefaceUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ public class TypefaceUtils {
7777
*/
7878
public static final char ICON_ADD_MEMBER = '\uf21A';
7979

80+
/**
81+
* Public mirror repository icon
82+
*/
83+
public static final char ICON_MIRROR_PUBLIC = '\uf224';
84+
85+
/**
86+
* Public mirror repository icon
87+
*/
88+
public static final char ICON_MIRROR_PRIVATE = '\uf225';
89+
8090
/**
8191
* Follow icon
8292
*/

0 commit comments

Comments
 (0)