--- android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java 2010/04/23 14:13:39 662 +++ android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java 2010/04/23 15:23:44 663 @@ -60,6 +60,37 @@ } return response; } + + private void loadComments(String appId, MarketSession session, String locale, ArrayList commentBeans) { + CommentCallback commentsCb = new CommentCallback(); + commentsCb.setList( commentBeans ); + + commentsCb.setLocale( locale ); + session.setLocale( new Locale(locale) ); + + + int start = 0; + do { + int count = 10; + if (start > 0) + count = Math.min(10, commentsCb.getEntryCount() ); + + log.warning("count=" + count + " start=" + start + " " + locale); + CommentsRequest commentsRequest = CommentsRequest.newBuilder() + .setAppId(appId) + .setStartIndex(start) + .setEntriesCount(count) + .build(); + + session.append(commentsRequest, commentsCb); + session.flush(); + start +=10; + + if (start >= 30) + break; //emergency brake + + } while ( start < commentsCb.getEntryCount() ); + } protected String doLookupWorker(String appId) { @@ -76,55 +107,19 @@ .setWithExtendedInfo(true) .build(); - CommentsRequest commentsRequest = CommentsRequest.newBuilder() - .setAppId(appId) - .setStartIndex(0) - .setEntriesCount(10) - .build(); - - - - Callback appsCb = new Callback() { - @Override - public void onResult(ResponseContext context, AppsResponse response) { - //System.out.println("Response : " + response); - //sb.append("Response: " + response + "\n"); - - Formatter form = new Formatter(sb); - App app = response.getApp(0); - sb.append( "

" + app.getTitle() + "

"); - sb.append("Ver: " + app.getVersion() + " (" + app.getVersionCode() + ")\n" ); - sb.append("Ratingcount: " + app.getRatingsCount() + "\n"); - - sb.append("Rating: " ); - double rating = Double.parseDouble( app.getRating() ); - form.format("%.4f", rating); - sb.append("\n"); - - sb.append("Downloads: " + app.getExtendedInfo().getDownloadsCountText() + " (" + app.getExtendedInfo().getDownloadsCount() + ")\n" ); - - sb.append("\n"); - - } - }; + AppsCallback appsCb = new AppsCallback() ; + appsCb.setStringBuffer(sb); ArrayList commentBeans = new ArrayList(); - CommentCallback commentsCb = new CommentCallback(); - commentsCb.setList( commentBeans ); - commentsCb.setLocale("en"); - session.setLocale( Locale.ENGLISH ); session.append(appsRequest, appsCb); - session.append(commentsRequest, commentsCb); session.flush(); - commentsCb.setLocale( "da" ); - session.setLocale( new Locale("da") ); - session.append(commentsRequest, commentsCb); - session.flush(); + loadComments(appId, session, "da", commentBeans); + loadComments(appId, session, "en", commentBeans); Collections.sort(commentBeans); @@ -137,6 +132,7 @@ sb.append("\n"); } + sb.append("Comments: " + commentBeans.size() ); return sb.toString();