Exemple #1
0
    @Override
    protected Boolean doInBackground(Boolean... params) {

      allStats = db.getAllAppsLatestStats(accountname);

      for (AppInfo appInfo : allStats) {

        if (!appInfo.isGhost()) {
          String admobSiteId = Preferences.getAdmobSiteId(Main.this, appInfo.getPackageName());
          if (admobSiteId != null) {
            List<Admob> admobStats =
                db.getAdmobStats(admobSiteId, Timeframe.LAST_TWO_DAYS).getAdmobs();
            if (admobStats.size() > 0) {
              Admob admob = admobStats.get(admobStats.size() - 1);
              appInfo.setAdmobStats(admob);
            }
          }
          filteredStats.add(appInfo);
        }
      }

      triggerRemoteCall = params[0];

      return null;
    }
Exemple #2
0
    @Override
    protected Boolean doInBackground(List<AppInfo>... params) {

      List<AppInfo> appInfos = params[0];

      Boolean success = false;

      for (AppInfo appInfo : appInfos) {

        String iconUrl = appInfo.getIconUrl();

        if (iconUrl != null) {

          File iconFile = new File(getCacheDir() + "/" + appInfo.getIconName());
          if (!iconFile.exists()) {

            try {
              iconFile.createNewFile();
              URL url = new URL(iconUrl);
              HttpURLConnection c = (HttpURLConnection) url.openConnection();
              c.setRequestMethod("GET");
              // c.setDoOutput(true);
              c.connect();

              FileOutputStream fos = new FileOutputStream(iconFile);

              InputStream is = c.getInputStream();

              byte[] buffer = new byte[1024];
              int len1 = 0;
              while ((len1 = is.read(buffer)) != -1) {
                fos.write(buffer, 0, len1);
              }
              fos.close();
              is.close();

              success = true;
            } catch (IOException e) {

              if (iconFile.exists()) {
                iconFile.delete();
              }

              Log.d("log_tag", "Error: " + e);
            }
          }
        }
      }

      return success;
    }
Exemple #3
0
    @SuppressWarnings("unchecked")
    @Override
    protected Exception doInBackground(String... params) {

      // authentication failed before, retry with token invalidation

      Exception exception = null;

      String authtoken = ((AndlyticsApp) getApplication()).getAuthToken();

      List<AppInfo> appDownloadInfos = null;
      try {

        DeveloperConsole console = new DeveloperConsole(Main.this);
        appDownloadInfos = console.getAppDownloadInfos(authtoken, accountname);

        if (cancelRequested) {
          cancelRequested = false;
          return null;
        }

        Map<String, List<String>> admobAccountSiteMap = new HashMap<String, List<String>>();

        for (AppInfo appDownloadInfo : appDownloadInfos) {
          // update in database
          db.insertOrUpdateStats(appDownloadInfo);
          String admobSiteId =
              Preferences.getAdmobSiteId(Main.this, appDownloadInfo.getPackageName());
          if (admobSiteId != null) {
            String admobAccount = Preferences.getAdmobAccount(Main.this, admobSiteId);
            if (admobAccount != null) {
              List<String> siteList = admobAccountSiteMap.get(admobAccount);
              if (siteList == null) {
                siteList = new ArrayList<String>();
              }
              siteList.add(admobSiteId);
              admobAccountSiteMap.put(admobAccount, siteList);
            }
          }
        }

        // sync admob accounts
        Set<String> admobAccuntKeySet = admobAccountSiteMap.keySet();
        for (String admobAccount : admobAccuntKeySet) {

          AdmobRequest.syncSiteStats(
              admobAccount, Main.this, admobAccountSiteMap.get(admobAccount), null);
        }

        new LoadIconInCache().execute(appDownloadInfos);

      } catch (Exception e) {

        if (e instanceof IOException) {
          e = new NetworkException(e);
        }

        exception = e;

        Log.e(TAG, "error while requesting developer console", e);
      }

      if (dotracking == true) {
        int size = 0;
        if (appDownloadInfos != null) {
          size = appDownloadInfos.size();
        }
        // TODO endless loop in case of exception!!!
        if (exception == null) {
          Map<String, String> map = new HashMap<String, String>();
          map.put("num", size + "");
        } else {
        }
        dotracking = false;
      }

      return exception;
    }