Skip to content

Commit 98bf653

Browse files
committed
Load repository when owner avatar url is missing
This denotes the repository was loaded with incomplete data and should be fully loaded before determining what pages to show.
1 parent c2c9018 commit 98bf653

3 files changed

Lines changed: 80 additions & 3 deletions

File tree

app/res/layout/pager_with_title.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@
1818
xmlns:app="http://schemas.android.com/apk/res/com.github.mobile"
1919
android:layout_width="match_parent"
2020
android:layout_height="match_parent"
21+
android:gravity="center"
2122
android:orientation="vertical" >
2223

24+
<ProgressBar
25+
android:id="@+id/pb_loading"
26+
style="@style/Spinner"
27+
android:layout_width="64dp"
28+
android:layout_height="64dp"
29+
android:visibility="gone" />
30+
2331
<com.viewpagerindicator.TitlePageIndicator
2432
android:id="@+id/tpi_header"
2533
android:layout_width="match_parent"

app/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<string name="error_orgs_load">Loading account &amp; organizations failed</string>
2121
<string name="error_issues_load">Loading issues failed</string>
2222
<string name="error_repos_load">Loading repositories failed</string>
23+
<string name="error_repo_load">Loading repository failed</string>
2324
<string name="error_gist_load">Loading Gist failed</string>
2425
<string name="error_news_load">Loading news failed</string>
2526
<string name="error_followers_load">Loading followers failed</string>

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

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,36 @@
1717

1818
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
1919
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
20+
import static android.view.View.GONE;
21+
import static android.view.View.VISIBLE;
2022
import static com.github.mobile.Intents.EXTRA_REPOSITORY;
23+
import android.content.Context;
2124
import android.content.Intent;
2225
import android.os.Bundle;
2326
import android.support.v4.view.ViewPager;
27+
import android.widget.ProgressBar;
2428

2529
import com.actionbarsherlock.app.ActionBar;
2630
import com.actionbarsherlock.view.MenuItem;
2731
import com.github.mobile.Intents.Builder;
2832
import com.github.mobile.R.id;
2933
import com.github.mobile.R.layout;
34+
import com.github.mobile.R.string;
35+
import com.github.mobile.accounts.AuthenticatedUserTask;
3036
import com.github.mobile.ui.user.HomeActivity;
3137
import com.github.mobile.util.AvatarLoader;
38+
import com.github.mobile.util.ToastUtils;
3239
import com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockFragmentActivity;
3340
import com.google.inject.Inject;
3441
import com.viewpagerindicator.TitlePageIndicator;
3542

43+
import org.eclipse.egit.github.core.IRepositoryIdProvider;
3644
import org.eclipse.egit.github.core.Repository;
45+
import org.eclipse.egit.github.core.User;
46+
import org.eclipse.egit.github.core.service.RepositoryService;
3747

3848
import roboguice.inject.InjectExtra;
49+
import roboguice.inject.InjectView;
3950

4051
/**
4152
* Activity to view a repository
@@ -52,12 +63,39 @@ public static Intent createIntent(Repository repository) {
5263
return new Builder("repo.VIEW").repo(repository).toIntent();
5364
}
5465

66+
private static class RefreshTask extends AuthenticatedUserTask<Repository> {
67+
68+
@Inject
69+
private RepositoryService service;
70+
71+
private final IRepositoryIdProvider repo;
72+
73+
public RefreshTask(Context context, IRepositoryIdProvider repo) {
74+
super(context);
75+
76+
this.repo = repo;
77+
}
78+
79+
protected Repository run() throws Exception {
80+
return service.getRepository(repo);
81+
}
82+
}
83+
5584
@InjectExtra(EXTRA_REPOSITORY)
5685
private Repository repository;
5786

5887
@Inject
5988
private AvatarLoader avatarHelper;
6089

90+
@InjectView(id.vp_pages)
91+
private ViewPager pager;
92+
93+
@InjectView(id.pb_loading)
94+
private ProgressBar loadingBar;
95+
96+
@InjectView(id.tpi_header)
97+
private TitlePageIndicator indicator;
98+
6199
@Override
62100
protected void onCreate(Bundle savedInstanceState) {
63101
super.onCreate(savedInstanceState);
@@ -68,12 +106,42 @@ protected void onCreate(Bundle savedInstanceState) {
68106
actionBar.setTitle(repository.getName());
69107
actionBar.setSubtitle(repository.getOwner().getLogin());
70108
actionBar.setDisplayHomeAsUpEnabled(true);
71-
avatarHelper.bind(actionBar, repository.getOwner());
72109

73-
ViewPager pager = (ViewPager) findViewById(id.vp_pages);
110+
User owner = repository.getOwner();
111+
if (owner != null && owner.getAvatarUrl() != null)
112+
configurePager();
113+
else {
114+
loadingBar.setVisibility(VISIBLE);
115+
pager.setVisibility(GONE);
116+
indicator.setVisibility(GONE);
117+
new RefreshTask(this, repository) {
118+
119+
@Override
120+
protected void onSuccess(Repository fullRepository) throws Exception {
121+
super.onSuccess(fullRepository);
122+
123+
repository = fullRepository;
124+
configurePager();
125+
}
126+
127+
@Override
128+
protected void onException(Exception e) throws RuntimeException {
129+
super.onException(e);
130+
131+
ToastUtils.show(RepositoryViewActivity.this, string.error_repo_load);
132+
}
133+
}.execute();
134+
}
135+
}
136+
137+
private void configurePager() {
138+
avatarHelper.bind(getSupportActionBar(), repository.getOwner());
139+
loadingBar.setVisibility(GONE);
140+
pager.setVisibility(VISIBLE);
141+
indicator.setVisibility(VISIBLE);
74142
pager.setAdapter(new RepositoryPagerAdapter(getSupportFragmentManager(), getResources(), repository
75143
.isHasIssues()));
76-
((TitlePageIndicator) findViewById(id.tpi_header)).setViewPager(pager);
144+
indicator.setViewPager(pager);
77145
}
78146

79147
@Override

0 commit comments

Comments
 (0)