Skip to content

Commit 6716c22

Browse files
committed
Fire back to acitivity when Gist loads
Ensures the avatar is updated when the Gist is initially opened with just an id and then a full load begins
1 parent f6726e8 commit 6716c22

File tree

3 files changed

+64
-13
lines changed

3 files changed

+64
-13
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2012 GitHub Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.mobile.core;
17+
18+
/**
19+
* Load listener callback
20+
*
21+
* @param <V>
22+
*/
23+
public interface OnLoadListener<V> {
24+
25+
/**
26+
* Loaded callback
27+
*
28+
* @param data
29+
*/
30+
void loaded(V data);
31+
}

app/src/main/java/com/github/mobile/ui/gist/GistFragment.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.content.Intent;
2626
import android.graphics.Typeface;
2727
import android.os.Bundle;
28+
import android.support.v4.app.FragmentActivity;
2829
import android.text.TextUtils;
2930
import android.view.LayoutInflater;
3031
import android.view.View;
@@ -44,6 +45,7 @@
4445
import com.github.mobile.R.menu;
4546
import com.github.mobile.R.string;
4647
import com.github.mobile.accounts.AccountUtils;
48+
import com.github.mobile.core.OnLoadListener;
4749
import com.github.mobile.core.gist.FullGist;
4850
import com.github.mobile.core.gist.GistStore;
4951
import com.github.mobile.core.gist.RefreshGistTask;
@@ -387,13 +389,19 @@ protected void onException(Exception e) throws RuntimeException {
387389
ToastUtils.show(getActivity(), e, string.error_gist_load);
388390
}
389391

392+
@SuppressWarnings("unchecked")
390393
@Override
391394
protected void onSuccess(FullGist fullGist) throws Exception {
392395
super.onSuccess(fullGist);
393396

394397
if (!isUsable())
395398
return;
396399

400+
FragmentActivity activity = getActivity();
401+
if (activity instanceof OnLoadListener)
402+
((OnLoadListener<Gist>) activity)
403+
.loaded(fullGist.getGist());
404+
397405
starred = fullGist.isStarred();
398406
loadFinished = true;
399407
gist = fullGist.getGist();

app/src/main/java/com/github/mobile/ui/gist/GistsViewActivity.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.github.mobile.R.id;
3232
import com.github.mobile.R.layout;
3333
import com.github.mobile.R.string;
34+
import com.github.mobile.core.OnLoadListener;
3435
import com.github.mobile.core.gist.GistStore;
3536
import com.github.mobile.ui.ConfirmDialogFragment;
3637
import com.github.mobile.ui.FragmentProvider;
@@ -48,7 +49,8 @@
4849
/**
4950
* Activity to display a collection of Gists in a pager
5051
*/
51-
public class GistsViewActivity extends PagerActivity {
52+
public class GistsViewActivity extends PagerActivity implements
53+
OnLoadListener<Gist> {
5254

5355
private static final int REQUEST_CONFIRM_DELETE = 1;
5456

@@ -166,9 +168,27 @@ public void onDialogResult(int requestCode, int resultCode, Bundle arguments) {
166168
public void onPageSelected(int position) {
167169
super.onPageSelected(position);
168170

169-
ActionBar actionBar = getSupportActionBar();
170171
String gistId = gists[position];
171172
Gist gist = store.getGist(gistId);
173+
updateActionBar(gist, gistId);
174+
}
175+
176+
@Override
177+
public void startActivity(Intent intent) {
178+
Intent converted = urlLauncher.convert(intent);
179+
if (converted != null)
180+
super.startActivity(converted);
181+
else
182+
super.startActivity(intent);
183+
}
184+
185+
@Override
186+
protected FragmentProvider getProvider() {
187+
return adapter;
188+
}
189+
190+
private void updateActionBar(Gist gist, String gistId) {
191+
ActionBar actionBar = getSupportActionBar();
172192
if (gist == null) {
173193
actionBar.setSubtitle(null);
174194
actionBar.setLogo(null);
@@ -185,16 +205,8 @@ public void onPageSelected(int position) {
185205
}
186206

187207
@Override
188-
public void startActivity(Intent intent) {
189-
Intent converted = urlLauncher.convert(intent);
190-
if (converted != null)
191-
super.startActivity(converted);
192-
else
193-
super.startActivity(intent);
194-
}
195-
196-
@Override
197-
protected FragmentProvider getProvider() {
198-
return adapter;
208+
public void loaded(Gist gist) {
209+
if (gists[pager.getCurrentItem()].equals(gist.getId()))
210+
updateActionBar(gist, gist.getId());
199211
}
200212
}

0 commit comments

Comments
 (0)