Ejemplo n.º 1
0
 default PageBean calcPage(final int max, final int pageNo, final int pageSize) {
   PageBean page = new PageBean();
   page.setTotalCount(max);
   page.setCurrentPage(currentPage(pageNo) + 1);
   page.setMaxPage(maxPage(max, pageSize));
   return page;
 }
Ejemplo n.º 2
0
 /**
  * 获得应用排行榜信息
  *
  * @return
  */
 public List<AppsBean> getTopAppsList(String action_url) {
   AppLog.d(TAG, "---getApps---action_url=" + action_url + ";pageNo=" + pageBean.getPageNo());
   param.put(RequestParam.Param.PAGENO, String.valueOf(pageBean.getPageNo()));
   param.put(RequestParam.Param.LINENUMBER, String.valueOf(pageBean.getPageSize()));
   String jsonStr = mNetUtil.getAppsByStatus(param, RequestParam.SERVICE_ACTION_URL + action_url);
   if (jsonStr.equals(RequestParam.NET_ERROR)) {
     return null;
   }
   List<AppsBean> tempList = new ArrayList<AppsBean>();
   try {
     JSONObject jsonObj = new JSONObject(jsonStr);
     if (null == jsonObj) {
       pageBean.calculatePageTotal(0);
       return tempList;
     }
     JSONObject pageObj = jsonObj.getJSONObject("page");
     if (null == jsonObj) {
       pageBean.calculatePageTotal(0);
       return tempList;
     }
     JSONArray listArr = pageObj.getJSONArray("list");
     Object pageTotal = pageObj.get("totalLine");
     pageBean.calculatePageTotal(Integer.valueOf(pageTotal.toString()));
     JSONObject appObj;
     setPath();
     for (int i = 0; i < listArr.length(); i++) {
       appObj = listArr.getJSONObject(i);
       AppsBean apps = new AppsBean();
       apps.setID(appObj.getInt("id"));
       apps.setAppName(appObj.getString("name"));
       apps.setPrice(appObj.getDouble("price"));
       String imageSrc = appObj.getString("image");
       String[] tempStr = imageSrc.split("/");
       apps.setNatImageUrl(path + tempStr[tempStr.length - 1]);
       apps.setSerImageUrl(RequestParam.SERVICE_IMAGE_URL + imageSrc);
       if (appObj.getString("id") != null
           && !appObj.getString("id").equals("")
           && appObj.getString("id") != null
           && !appObj.getString("id").equals("")
           && appObj.getString("name") != null
           && !appObj.getString("name").equals("")) {
         tempList.add(apps);
       }
     }
   } catch (JSONException e) {
     AppLog.d(TAG, "*********error************* getRecommendAppsList json is error");
     e.printStackTrace();
   }
   if (pageBean.getPageTotal() == 0) {
     pageBean.setPageNo(0);
   }
   //        loadListImage(tempList,AppStoreActivity.MSG_FINISH_ONE_APP);
   return tempList;
 }
Ejemplo n.º 3
0
 /**
  * @param cu cache对象
  * @param page 分页对新
  * @param objectName 索引值(相当于key-value中的key)
  * @return 一个存储所需数据对象的List
  */
 public static List loadByCache(CacheUtil cu, PageBean page, String objectName) {
   List back = null;
   List result = (List) cu.getCacheObject(objectName);
   if (result != null) {
     back = new ArrayList();
     int count =
         (Integer.parseInt(page.getPageIndex()) - 1) * Integer.parseInt(page.getPageCount());
     int length = result.size();
     for (int i = count;
         i
             < ((count + Integer.parseInt(page.getPageCount())) < length
                 ? (count + Integer.parseInt(page.getPageCount()))
                 : length);
         i++) {
       back.add(result.get(i));
     }
   }
   return back;
 }
Ejemplo n.º 4
0
 /**
  * 获取已安装或已升级应用的分页数据
  *
  * @return
  */
 public List<ApplicationBean> getOnePageAppsList(List<ApplicationBean> all) {
   List<ApplicationBean> tempList = new ArrayList<ApplicationBean>();
   if (null == all || all.size() < 1) {
     return tempList;
   }
   if (all.size() <= pageBean.getPageSize()) {
     return all;
   } else {
     int startIndex, endIndex;
     int pageNo = pageBean.getPageNo();
     startIndex = (pageNo - 1) * pageBean.getPageSize();
     endIndex = pageNo * pageBean.getPageSize();
     if (pageNo == pageBean.getPageTotal()) {
       endIndex = all.size();
     }
     for (int i = startIndex; i < endIndex; i++) {
       tempList.add(all.get(i));
     }
   }
   return tempList;
 }
Ejemplo n.º 5
0
  /**
   * 根据分类id获得应用信息
   *
   * @return
   */
  public List<AppsBean> getAppsSearchList(String action_url) {
    AppLog.d(
        TAG,
        "---getApps---action_url="
            + action_url
            + ";pageNo="
            + pageBean.getPageNo()
            + pageBean.getKeyWord());
    //        if(typeId>=0){
    //            param.put(RequestParam.Param.TYPEID,String.valueOf(typeId));
    //        }
    //        param.put(RequestParam.Param.PAGENO,String.valueOf(pageBean.getPageNo()));
    //        param.put(RequestParam.Param.LINENUMBER, String.valueOf(pageBean.getPageSize()));
    param.put(RequestParam.Param.KEYWORD, pageBean.getKeyWord());

    String jsonStr = mNetUtil.getAppsByStatus(param, RequestParam.SERVICE_ACTION_URL + action_url);
    if (jsonStr.equals(RequestParam.NET_ERROR)) {
      return null;
    }
    List<AppsBean> tempList = new ArrayList<AppsBean>();
    try {
      JSONObject allObj = new JSONObject(jsonStr);
      if (null == allObj) {
        pageBean.calculatePageTotal(0);
        return tempList;
      }
      JSONObject pageObj = allObj.getJSONObject("page");
      JSONArray listArr = pageObj.getJSONArray("list");
      Object pageTotal = pageObj.get("totalLine");
      if (Integer.valueOf(pageTotal.toString()) == 0) {
        pageBean.calculatePageTotal(0);
        return tempList;
      }
      pageBean.calculatePageTotal(Integer.valueOf(pageTotal.toString()));
      JSONObject appObj;
      setPath();
      for (int i = 0; i < listArr.length(); i++) {
        appObj = listArr.getJSONObject(i);
        AppsBean apps = new AppsBean();
        apps.setID(appObj.getInt("id"));
        apps.setAppName(appObj.getString("name"));
        //                String typeIDStr=appObj.getString("typeId");
        //                apps.setTypeID(typeIDStr.equals("")?-1:Integer.valueOf(typeIDStr));
        apps.setVersion("(" + appObj.getString("version") + ")");
        apps.setTypeName(
            "" + appObj.getString("typeNames").replace("[", "").replace("\"", "").replace("]", ""));
        String imageSrc = appObj.getString("image");
        String[] tempStr = imageSrc.split("/");
        apps.setNatImageUrl(path + tempStr[tempStr.length - 1]);
        apps.setSerImageUrl(RequestParam.SERVICE_IMAGE_URL + imageSrc);
        if (appObj.getString("id") != null
            && !appObj.getString("id").equals("")
            && appObj.getString("id") != null
            && !appObj.getString("id").equals("")
            && appObj.getString("name") != null
            && !appObj.getString("name").equals("")) {
          tempList.add(apps);
        }
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return tempList;
  }