/** * 刷新ui * * @param task */ private void reshUI(final DownloadTask task) { if (task.getStatus() == DownloadTask.DOWNLOAD_FINISH) { new Thread() { @Override public void run() { boolean isExists = SkinThemeDB.getSkinThemeDB(context).skinThemeIsExists(task.getTid()); if (!isExists) { // 往皮肤数据库添加数据 SkinThemeApp skinTheme = new SkinThemeApp(); skinTheme.setID(task.getTid()); skinTheme.setThemeName(task.gettName()); skinTheme.setAssetsType(SkinThemeApp.NET); skinTheme.setAddTime(DateUtil.dateToString(new Date())); skinTheme.setDownloadPath(task.getFilePath()); // 解压皮肤文件 String path = context.getFilesDir().getParent() + File.separator + "files"; String outputDirectory = path + File.separator + "skin" + File.separator + task.getTid(); String zipPath = task.getFilePath(); String zipName = task.getTid(); skinTheme.setUnZipPath(outputDirectory); SkinThemeDB.getSkinThemeDB(context).add(skinTheme); UnzipUtil.unZip(context, zipName, zipPath, outputDirectory); Message msg = new Message(); msg.obj = skinTheme; ObserverManage.getObserver().setMessage(msg); } } }.start(); ToastUtil.showText("皮肤: " + task.gettName() + " 下载完成"); } for (int i = 0; i < datas.size(); i++) { DownloadTask temp = datas.get(i); if (task.getTid().equals(temp.getTid())) { datas.remove(i); datas.add(i, task); reshPICStatusUI(i); break; } } }
/** * 查找已选择的主题皮肤的索引 * * @return */ private int findOldSelectedIndex() { if (datas != null && datas.size() != 0) { for (int i = 0; i < datas.size(); i++) { DownloadTask downloadTask = datas.get(i); if (downloadTask.getTid().equals(Constants.skinID)) { return i; } } } return -1; }
@Override public void onBindViewHolder(final ItemViewHolder itemViewHolder, final int position) { final DownloadTask downloadTask = datas.get(position); String sid = downloadTask.getTid(); String imageUrl = HttpUtil.getSkinThemePreviewImageByID(sid); ImageLoadUtil.loadImageFormUrl( imageUrl, itemViewHolder.getImavPic(), R.drawable.picture_manager_default, true); itemViewHolder.getMainTextView().setText(downloadTask.gettName() + ""); itemViewHolder.getSkinSizeTextView().setText(getFileSize(downloadTask.getFileSize()) + ""); itemViewHolder.getSkinProgressBar().setMax((int) downloadTask.getFileSize()); itemViewHolder.getSkinProgressBar().setProgress((int) downloadTask.getDownloadedSize()); reshViewHolder(position, itemViewHolder, downloadTask); }
/** * 加载皮肤 * * @param position * @param downloadTask * @param itemViewHolder */ protected void loadSkin(int position, DownloadTask downloadTask, ItemViewHolder itemViewHolder) { selectedIndex = findOldSelectedIndex(); if (selectedIndex != -1) { reshPICStatusUI(selectedIndex); } // 设置当前皮肤主题的id和保存,并通知各个页面去加载新的皮肤 Constants.skinID = downloadTask.getTid(); DataUtil.saveValue(context, Constants.skinID_KEY, Constants.skinID); SkinThemeApp skinTheme = SkinThemeDB.getSkinThemeDB(context).getSkinThemeInfo(Constants.skinID); if (skinTheme != null) { DataUtil.loadSkin(context); ObserverManage.getObserver().setMessage(skinTheme); } selectedIndex = position; reshPICStatusUI(selectedIndex); }
/** * 刷新ui * * @param position * @param itemViewHolder * @param downloadTask */ private void reshViewHolder( final int position, final ItemViewHolder itemViewHolder, final DownloadTask downloadTask) { if (SkinThemeDB.getSkinThemeDB(context).skinThemeIsExists(downloadTask.getTid())) { // itemViewHolder.getDownloadstatusRelativeLayout().setVisibility( // View.INVISIBLE); // itemViewHolder.getSkinProgressBar().setVisibility(View.INVISIBLE); if (!downloadTask.getTid().equals(Constants.skinID)) { itemViewHolder.getselectImageView().setVisibility(View.INVISIBLE); itemViewHolder .getItembg() .setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { // 加载皮肤数据 loadSkin(position, downloadTask, itemViewHolder); } }); } else { itemViewHolder.getItembg().setOnClickListener(null); // selectedIndex = position; itemViewHolder.getselectImageView().setVisibility(View.VISIBLE); } itemViewHolder.getSkinProgressBar().setVisibility(View.INVISIBLE); itemViewHolder.getDownloadstatusRelativeLayout().setVisibility(View.INVISIBLE); } else { itemViewHolder.getselectImageView().setVisibility(View.INVISIBLE); if (downloadTask.getStatus() == DownloadTask.DOWNLOAD_FINISH) { itemViewHolder.getSkinProgressBar().setVisibility(View.INVISIBLE); itemViewHolder.getDownloadstatusRelativeLayout().setVisibility(View.INVISIBLE); itemViewHolder .getItembg() .setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { // 加载皮肤数据 loadSkin(position, downloadTask, itemViewHolder); } }); } else if (downloadTask.getStatus() == DownloadTask.DOWNLOING || downloadTask.getStatus() == DownloadTask.WAITING) { itemViewHolder.getSkinProgressBar().setVisibility(View.VISIBLE); itemViewHolder.getDownloadstatusRelativeLayout().setVisibility(View.INVISIBLE); itemViewHolder.getItembg().setOnClickListener(null); } else { itemViewHolder.getSkinProgressBar().setVisibility(View.INVISIBLE); itemViewHolder.getDownloadstatusRelativeLayout().setVisibility(View.VISIBLE); itemViewHolder .getItembg() .setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { // 下载皮肤 downloadSkin(position, downloadTask); } }); } } }