Skip to content

Commit fa1d19e

Browse files
committed
bug fixes.
1 parent 5709021 commit fa1d19e

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/com/ysaito/shogi/GameLogListActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public String getListLabel(GameLog log) {
9999

100100
@Override
101101
public GameLog[] readNthStream(int index) throws Throwable {
102-
Collection<GameLog> list = GameLogListManager.getInstance().listLogs(this, mMode);
102+
Collection<GameLog> list = mGameLogList.listLogs(this, mMode);
103103
return list.toArray(new GameLog[0]);
104104
}
105105

src/com/ysaito/shogi/GenericListActivity.java

+18-8
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,19 @@ protected void initialize(
147147
setListAdapter(mAdapter);
148148
}
149149

150+
private static enum ListingMode {
151+
DELETE_EXISTING_OBJECTS,
152+
ADD_TO_EXISTING_OBJECTS,
153+
};
154+
150155
private static class ListingStatus<T> {
151-
public ListingStatus(T[] o, boolean d) {
156+
public ListingStatus(T[] o, ListingMode m) {
152157
objects = o;
153-
deleteExistingObjects = d;
158+
mode = m;
154159
}
155160

156161
public final T[] objects;
157-
public final boolean deleteExistingObjects;
162+
public final ListingMode mode;
158163
}
159164

160165
/**
@@ -251,20 +256,25 @@ protected String doInBackground(Integer... mode) {
251256
} else {
252257
r = mCache.read(mCacheKey, mMaxCacheStalenessMillis);
253258
}
254-
final boolean hitCache = (r.obj != null);
259+
final boolean hitCache = (r.obj != null);
255260
if (hitCache) {
256-
publishProgress(new ListingStatus<T>((T[])r.obj, false));
261+
publishProgress(new ListingStatus<T>((T[])r.obj, ListingMode.DELETE_EXISTING_OBJECTS));
257262
}
263+
258264
if (r.needRefresh) {
259265
ArrayList<T> aggregate = new ArrayList<T>();
260266
fetcher = new ParallelFetcher();
267+
boolean firstPublish = true;
261268
while (fetcher.hasNext()) {
262269
T[] objs = fetcher.next();
263270
if (objs != null) {
264271
for (T obj: objs) aggregate.add(obj);
265272
if (!hitCache) {
266273
// Incrementally update the screen as results arrive
267-
publishProgress(new ListingStatus<T>(objs, false));
274+
publishProgress(new ListingStatus<T>(objs,
275+
(firstPublish ? ListingMode.DELETE_EXISTING_OBJECTS :
276+
ListingMode.ADD_TO_EXISTING_OBJECTS)));
277+
firstPublish = false;
268278
} else {
269279
// If the screen was already filled with a stale cache,
270280
// buffer the new contents until it is complete, so that
@@ -276,7 +286,7 @@ protected String doInBackground(Integer... mode) {
276286
T[] objs = aggregate.toArray(mTmpArray);
277287
if (mCacheKey != null) mCache.write(mCacheKey, objs);
278288
if (hitCache) {
279-
publishProgress(new ListingStatus<T>(objs, true));
289+
publishProgress(new ListingStatus<T>(objs, ListingMode.DELETE_EXISTING_OBJECTS));
280290
}
281291
}
282292
}
@@ -297,7 +307,7 @@ protected String doInBackground(Integer... mode) {
297307
@Override
298308
protected void onProgressUpdate(ListingStatus<T>... list) {
299309
for (ListingStatus<T> status : list) {
300-
if (status.deleteExistingObjects) {
310+
if (status.mode == ListingMode.DELETE_EXISTING_OBJECTS) {
301311
mAdapter.setObjects(status.objects);
302312
} else {
303313
mAdapter.addObjects(status.objects);

0 commit comments

Comments
 (0)