Ejemplo n.º 1
0
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   userJSON = FileUtil.readConfigFile(userConfigPath);
   pgyerJSON = FileUtil.readConfigFile(pgyerVersionPath);
   notificationJSON = FileUtil.readConfigFile(notificationPath);
   try {
     String currentUIVersion = URLs.currentUIVersion(mContext);
     kpiUrl =
         String.format(
             K.kKPIMobilePath,
             K.kBaseUrl,
             currentUIVersion,
             userJSON.getString(URLs.kGroupId),
             userJSON.getString(URLs.kRoleId));
     analyseUrl =
         String.format(
             K.kAnalyseMobilePath, K.kBaseUrl, currentUIVersion, userJSON.getString(URLs.kRoleId));
     appUrl =
         String.format(
             K.kAppMobilePath, K.kBaseUrl, currentUIVersion, userJSON.getString(URLs.kRoleId));
     messageUrl =
         String.format(
             K.kMessageMobilePath,
             K.kBaseUrl,
             currentUIVersion,
             userJSON.getString(URLs.kRoleId),
             userJSON.getString(URLs.kGroupId),
             userJSON.getString("user_id"));
     thursdaySayUrl = String.format(K.kThursdaySayMobilePath, K.kBaseUrl, currentUIVersion);
   } catch (JSONException e) {
     e.printStackTrace();
   }
   notifitionTask();
   return super.onStartCommand(intent, flags, startId);
 }
Ejemplo n.º 2
0
  /*
   * 计算将要传递给 DashboardActivity 的通知数值
   */
  private void processDataCount() {
    try {
      kpiCount = getDataCount(URLs.kTabKpi, kpiUrl);
      analyseCount = getDataCount(URLs.kTabAnalyse, analyseUrl);
      appCount = getDataCount(URLs.kTabApp, appUrl);
      messageCount = getDataCount(URLs.kTabMessage, messageUrl);
      thursdaySayCount = getDataCount(URLs.kSettingThursdaySay, thursdaySayUrl);

      /*
       * 遍历获取 Tab 栏上需要显示的通知数量 ("tab_*" 的值)
       */
      String[] typeString = {
        URLs.kTabKpi, URLs.kTabAnalyse, URLs.kTabApp, URLs.kTabMessage, URLs.kSettingThursdaySay
      };
      int[] typeCount = {kpiCount, analyseCount, appCount, messageCount, thursdaySayCount};
      for (int i = 0; i < typeString.length; i++) {
        notificationJSON.put(
            typeString[i],
            Math.abs(typeCount[i] - notificationJSON.getInt(typeString[i] + "_last")));
        notificationJSON.put(typeString[i] + "_last", typeCount[i]);
      }

      if ((new File(pgyerVersionPath)).exists()) {
        pgyerJSON = FileUtil.readConfigFile(pgyerVersionPath);
        JSONObject responseData = pgyerJSON.getJSONObject(URLs.kData);
        pgyerCode = responseData.getString("versionCode");
        packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        versionCode = String.valueOf(packageInfo.versionCode);
        updataCount = pgyerCode.equals(versionCode) ? -1 : 1;
      } else {
        updataCount = -1;
      }

      passwordCount = userJSON.getString(URLs.kPassword).equals(URLs.MD5(K.kInitPassword)) ? 1 : -1;
      notificationJSON.put(URLs.kSettingPassword, passwordCount);
      notificationJSON.put(URLs.kSettingPgyer, updataCount);

      int settingCount =
          (notificationJSON.getInt(URLs.kSettingPassword) > 0
                  || notificationJSON.getInt(URLs.kSettingPgyer) > 0
                  || notificationJSON.getInt(URLs.kSettingThursdaySay) > 0)
              ? 1
              : 0;
      notificationJSON.put(URLs.kSetting, settingCount);

      FileUtil.writeFile(notificationPath, notificationJSON.toString());
    } catch (JSONException | IOException | PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }
  }