diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index e8773b8e..e47980e9 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,6 @@ proguard/ local.properties secure.properties /assets +private-strings.xml +res/values/private-strings.xml /gradle.properties diff --git a/res/raw/changelog.html b/res/raw/changelog.html index 9d886f8b..3c281ce8 100755 --- a/res/raw/changelog.html +++ b/res/raw/changelog.html @@ -50,6 +50,183 @@
  • Fixed disappearing comment reply button
  • +
  • v2.6.0 + +
  • +
  • v2.5.8 + +
  • +
  • v2.5.7 + +
  • +
  • v2.5.6 + +
  • +
  • v2.5.5 + +
  • +
  • v2.5.4 + +
  • +
  • v2.5.3 + +
  • +
  • v2.5.2 + +
  • +
  • v2.5.1 + +
  • +
  • v2.5.0 + +
  • +
  • v2.4.3 + +
  • +
  • v2.4.2 + +
  • +
  • v2.4.1 + +
  • +
  • v2.4.0 + +
  • +
  • v2.3.1 + +
  • +
  • v2.3 + +
  • +
  • v2.2.3 + +
  • +
  • v2.2.2 + +
  • +
  • v2.2.1 + +
  • +
  • v2.2.0 + +
  • +
  • v2.1.3 + +
  • +
  • v2.1.0 + +
  • +
  • v2.0.1 + +
  • +
  • v2.0.0 + +
  • + diff --git a/src/com/github/andlyticsproject/console/v2/DevConsoleV2.java b/src/com/github/andlyticsproject/console/v2/DevConsoleV2.java index b79e6ee9..62ddf54b 100644 --- a/src/com/github/andlyticsproject/console/v2/DevConsoleV2.java +++ b/src/com/github/andlyticsproject/console/v2/DevConsoleV2.java @@ -1,5 +1,21 @@ package com.github.andlyticsproject.console.v2; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.apache.http.HttpStatus; +import org.apache.http.client.CookieStore; +import org.apache.http.client.HttpResponseException; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.cookie.Cookie; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; + import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; @@ -15,34 +31,21 @@ import com.github.andlyticsproject.model.RevenueSummary; import com.github.andlyticsproject.util.Utils; -import org.apache.http.HttpStatus; -import org.apache.http.client.CookieStore; -import org.apache.http.client.HttpResponseException; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.cookie.Cookie; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.DefaultHttpClient; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - /** * This is a WIP class representing the new v2 version of the developer console. * The aim is to build it from scratch to make it a light weight and as well * documented at the end as possible. Once it is done and available to all * users, we will rip out the old code and replace it with this. - * + * * Once v2 is available to all users, there is scope for better utilising the * available statistics data, so keep that in mind when developing this class. * For now though, keep it simple and get it working. - * + * * See https://github.com/AndlyticsProject/andlytics/wiki/Developer-Console-v2 * for some more documentation - * + * * This class fetches the data, which is then passed using {@link JsonParser} - * + * */ @SuppressLint("DefaultLocale") public class DevConsoleV2 implements DevConsole { @@ -61,9 +64,10 @@ public class DevConsoleV2 implements DevConsole { private ResponseHandler responseHandler = HttpClientFactory.createResponseHandler(); + // This is only used for synchronising fetchAppInfosAndStatistics() + private CountDownLatch fetchAppInfoCounter; + public static DevConsoleV2 createForAccount(String accountName, DefaultHttpClient httpClient) { - // DevConsoleAuthenticator authenticator = new AccountManagerAuthenticator(accountName, - // httpClient); DevConsoleAuthenticator authenticator = new OauthAccountManagerAuthenticator(accountName, httpClient); @@ -88,7 +92,7 @@ private DevConsoleV2(DefaultHttpClient httpClient, DevConsoleAuthenticator authe /** * Gets a list of available apps for the given account - * + * * @param activity * @return * @throws DevConsoleException @@ -110,27 +114,70 @@ public synchronized List getAppInfo(Activity activity) throws DevConsol } } + private List fetchAppInfosAndStatistics() { // Fetch a list of available apps + ExecutorService executor = Executors.newFixedThreadPool(10); // Only process 10 at a time List apps = fetchAppInfos(); + fetchAppInfoCounter = new CountDownLatch(apps.size()); + + for (final AppInfo app : apps) { + /* + * Generate a new thread for each app. This removes the queueing behaviour so requests + * are made in parallel. + */ + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + Log.d("start app", app.getName()); + + // Fetch remaining app statistics + // Latest stats object, and active/total installs is fetched + // in fetchAppInfos + AppStats stats = app.getLatestStats(); + fetchRatings(app, stats); + stats.setNumberOfComments(fetchCommentsCount(app, Utils.getDisplayLocale())); + + RevenueSummary revenue = fetchRevenueSummary(app); + app.setTotalRevenueSummary(revenue); + // this is currently the same as the last item of the historical + // data, so save some cycles and don't parse historical + // XXX the definition of 'last day' is unclear: GMT? + if (revenue != null) { + stats.setTotalRevenue(revenue.getLastDay()); + } + + Log.d("end app", app.getName()); + } + finally { + Log.w("finally app", app.getName()); + + // Increment the number of successful fetches, then wake the lock. + synchronized (fetchAppInfoCounter) { + Log.e("fetch counter", String.valueOf(fetchAppInfoCounter.getCount())); + fetchAppInfoCounter.countDown(); + + Log.w("finally count", String.valueOf(fetchAppInfoCounter.getCount())); + } + } + } + }); - for (AppInfo app : apps) { - // Fetch remaining app statistics - // Latest stats object, and active/total installs is fetched - // in fetchAppInfos - AppStats stats = app.getLatestStats(); - fetchRatings(app, stats); - stats.setNumberOfComments(fetchCommentsCount(app, Utils.getDisplayLocale())); - - RevenueSummary revenue = fetchRevenueSummary(app); - app.setTotalRevenueSummary(revenue); - // this is currently the same as the last item of the historical - // data, so save some cycles and don't parse historical - // XXX the definition of 'last day' is unclear: GMT? - if (revenue != null) { - stats.setTotalRevenue(revenue.getLastDay()); - } + executor.execute(thread); + } + + + // Wait for lock to be triggered + // Keep waiting for the other threads to finish + try { + Log.e("Waiting", "waiting..."); + fetchAppInfoCounter.await(); } + catch (InterruptedException e) { + } + + Log.e("Waiting", "DONE!"); return apps; } @@ -138,7 +185,7 @@ private List fetchAppInfosAndStatistics() { /** * Gets a list of comments for the given app based on the startIndex and * count - * + * * @param accountName * @param packageName * @param startIndex @@ -192,7 +239,7 @@ private Comment replyToComment(String packageName, String developerId, String co /** * Fetches a combined list of apps for all avaiable console accounts - * + * * @return combined list of apps * @throws DevConsoleException */ @@ -251,10 +298,10 @@ private List fetchAppInfos() throws DevConsoleException { /** * Fetches statistics for the given packageName of the given statsType and * adds them to the given {@link AppStats} object - * + * * This is not used as statistics can be fetched via fetchAppInfos Can use * it later to get historical etc data - * + * * @param packageName * @param stats * @param statsType @@ -272,7 +319,7 @@ private void fetchStatistics(AppInfo appInfo, AppStats stats, int statsType) /** * Fetches ratings for the given packageName and adds them to the given {@link AppStats} object - * + * * @param packageName * The app to fetch ratings for * @param stats @@ -288,7 +335,7 @@ private void fetchRatings(AppInfo appInfo, AppStats stats) throws DevConsoleExce /** * Fetches the number of comments for the given packageName - * + * * @param packageName * @return * @throws DevConsoleException @@ -363,7 +410,7 @@ private boolean authenticateFromScratch(Activity activity) { /** * Logs into the Android Developer Console - * + * * @param reuseAuthentication * @throws DevConsoleException */