1717
1818import static android .content .Intent .FLAG_ACTIVITY_CLEAR_TOP ;
1919import static android .content .Intent .FLAG_ACTIVITY_SINGLE_TOP ;
20+ import static android .view .View .GONE ;
21+ import static android .view .View .VISIBLE ;
2022import static com .github .mobile .Intents .EXTRA_REPOSITORY ;
23+ import android .content .Context ;
2124import android .content .Intent ;
2225import android .os .Bundle ;
2326import android .support .v4 .view .ViewPager ;
27+ import android .widget .ProgressBar ;
2428
2529import com .actionbarsherlock .app .ActionBar ;
2630import com .actionbarsherlock .view .MenuItem ;
2731import com .github .mobile .Intents .Builder ;
2832import com .github .mobile .R .id ;
2933import com .github .mobile .R .layout ;
34+ import com .github .mobile .R .string ;
35+ import com .github .mobile .accounts .AuthenticatedUserTask ;
3036import com .github .mobile .ui .user .HomeActivity ;
3137import com .github .mobile .util .AvatarLoader ;
38+ import com .github .mobile .util .ToastUtils ;
3239import com .github .rtyley .android .sherlock .roboguice .activity .RoboSherlockFragmentActivity ;
3340import com .google .inject .Inject ;
3441import com .viewpagerindicator .TitlePageIndicator ;
3542
43+ import org .eclipse .egit .github .core .IRepositoryIdProvider ;
3644import org .eclipse .egit .github .core .Repository ;
45+ import org .eclipse .egit .github .core .User ;
46+ import org .eclipse .egit .github .core .service .RepositoryService ;
3747
3848import 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