Ejemplo n.º 1
0
 public final synchronized void updateProgress(String uid, int progress, int length) {
   int pro = progress >= 100 ? 100 : progress;
   String text = "";
   final ArrayList<HolderView> views = HolderViews;
   for (HolderView holder : views) {
     Task task = holder.task;
     if (task != null && task.getTransferUID().equals(uid)) {
       task.setTaskLength(length);
       task.setTaskProgress(pro);
       task.setState(Task.STATE.RUNNING);
       if (pro >= 100) {
         text = mContext.getString(R.string.ugc_label_task_verify);
       } else {
         text =
             getUploadDetail(task) /*+ " " + mContext.getString(R.string.label_task_live_speed)*/
                 + " "
                 + pro
                 + "%";
       }
       //
       holder.task_progress.setProgress(pro);
       holder.task_state_bnt.setBackgroundResource(R.drawable.ugc_ic_ioffer_upload_pause_icon);
       holder.task_detail.setText(text);
       //
       holder.task_progress.invalidate();
       holder.task_detail.invalidate();
       holder.task_state_bnt.invalidate();
       break;
     }
   }
 }
Ejemplo n.º 2
0
  public final void updateTaskState(UploadMessage msg) {

    String tuid = msg.mTuid;
    int state = msg.mState;
    final ArrayList<HolderView> views = HolderViews;

    for (HolderView holder : views) {

      Task task = holder.task;

      if (task != null && task.getTransferUID().equals(tuid)) {

        task.setState(state);
        task.setDetail(msg.mMessage);

        if (state == Task.STATE.NEW || state == Task.STATE.RUNNING) {
          holder.task_state_bnt.setBackgroundResource(R.drawable.ugc_ic_ioffer_upload_pause_icon);
        } else if (state == Task.STATE.WAIT) {
          holder.task_state_bnt.setBackgroundResource(R.drawable.ugc_ic_ioffer_upload_wait_icon);
        } else if (state == Task.STATE.STOP) {
          holder.task_state_bnt.setBackgroundResource(R.drawable.ugc_ic_ioffer_upload_resume_icon);
          holder.task_detail.setText(msg.mMessage);
          holder.task_detail.invalidate();
        } else if (state == Task.STATE.DONE) {
          notifyTaskListChange();
        }

        holder.task_state_bnt.invalidate();
        break;
      }
    }
  }
Ejemplo n.º 3
0
 private String getUploadDetail(Task task) {
   String detail = null;
   int total = task.getTaskLength();
   int prog = task.getTaskProgress();
   if (total > 0) {
     float p = (prog < 0) ? (0.00f) : ((float) prog / 100);
     detail =
         FLOAT_FORMAT.format((p * total) / B_LENGTH)
             + "MB / "
             + FLOAT_FORMAT.format(((float) total / B_LENGTH))
             + "MB";
   }
   return detail != null ? detail : task.getDetail();
 }
Ejemplo n.º 4
0
  public final void updateCompleteTask(boolean verify, String tuid) {

    final ArrayList<Task> list = mTaskList;

    for (Task task : list) {
      if (task.getTransferUID().equals(tuid)) {
        task.setTaskProgress(100);
        if (verify) task.setState(Task.STATE.DONE);
        else task.setState(Task.STATE.STOP);
        break;
      }
    }

    // 通知数据变化
    notifyTaskListChange();
  }
Ejemplo n.º 5
0
 private void updataTaskDoneCategory(HolderView holderview, Task task) {
   int type = task.getType();
   if (type == Task.TYPE.AUDIO) {
     holderview.history_category.setBackgroundResource(R.drawable.ugc_ic_ioffer_content_s_audio);
   } else if (type == Task.TYPE.VIDEO) {
     holderview.history_category.setBackgroundResource(R.drawable.ugc_ic_ioffer_content_s_video);
   } else if (type == Task.TYPE.IMAGE) {
     holderview.history_category.setBackgroundResource(R.drawable.ugc_ic_ioffer_content_s_image);
   }
 }
Ejemplo n.º 6
0
  private final void updateTaskState(Task task) {

    final ITaskStateListener listener = mTaskStateListener;
    int state = task.getState();

    if (state == Task.STATE.NEW || state == Task.STATE.RUNNING || state == Task.STATE.WAIT) {

      if (listener != null) listener.change(task, state, Task.STATE.STOP);

      task.setState(Task.STATE.STOP);

    } else if (state == Task.STATE.STOP) {

      if (listener != null) listener.change(task, state, Task.STATE.WAIT);

      task.setState(Task.STATE.WAIT);
    }

    notifyDataSetChanged();
  }
Ejemplo n.º 7
0
  /** 重新排序 */
  private void notifyTaskListChange() {

    mTaskTempList.clear();

    final ArrayList<Task> list = mTaskList;
    final ArrayList<Task> temp = mTaskTempList;

    // 排序
    Collections.sort(
        list,
        new Comparator<Task>() {

          @Override
          public int compare(Task t1, Task t2) {
            if (t1.getId() < t2.getId()) {
              return 1;
            } else {
              return -1;
            }
          }
        });

    // 正在上传
    for (Task task : list) {
      if (task.getState() == Task.STATE.RUNNING) {
        temp.add(task);
      }
    }
    // 等待
    for (Task task : list) {
      int state = task.getState();
      if (!temp.contains(task) && (state == Task.STATE.WAIT || state == Task.STATE.NEW)) {
        temp.add(task);
      }
    }
    // 停止
    for (Task task : list) {
      if (!temp.contains(task) && (task.getState() == Task.STATE.STOP)) {
        temp.add(task);
      }
    }
    // 完成
    for (Task task : list) {
      if (!temp.contains(task) && (task.getState() == Task.STATE.DONE)) {
        temp.add(task);
      }
    }
    //
    notifyDataSetChanged();
  }
Ejemplo n.º 8
0
 private void updataTaskIcon(HolderView holderview, Task task) {
   int type = task.getType();
   //
   if (type == Task.TYPE.AUDIO) {
     holderview.common_icon.setBackgroundResource(
         R.drawable.ugc_ic_ioffer_content_category_a_icon);
   } else if (type == Task.TYPE.VIDEO) {
     holderview.common_icon.setBackgroundResource(
         R.drawable.ugc_ic_ioffer_content_category_v_icon);
   } else if (type == Task.TYPE.IMAGE) {
     holderview.common_icon.setBackgroundResource(
         R.drawable.ugc_ic_ioffer_content_category_i_icon);
   }
 }
Ejemplo n.º 9
0
  private final void updateHolderView(HolderView holderview, final Task task, boolean hasListener) {

    Metadata meta = task.getMetadata();
    int state = task.getState();

    switch (state) {
      case Task.STATE.NEW:
      case Task.STATE.RUNNING:
        holderview.history_layout.setVisibility(View.GONE);
        holderview.history_state_layout.setVisibility(View.GONE);
        holderview.remove_layout.setVisibility(View.GONE);
        holderview.task_content_layout.setVisibility(View.VISIBLE);
        holderview.taks_state_layout.setVisibility(View.VISIBLE);
        holderview.task_title.setText(meta != null ? meta.getTitle() : "");
        holderview.task_state_bnt.setBackgroundResource(R.drawable.ugc_ic_ioffer_upload_pause_icon);
        holderview.task_progress.setProgress(task.getTaskProgress());
        holderview.task_detail.setText(getUploadDetail(task));
        if (hasListener) {
          holderview.task_state_bnt.setTag(task);
          holderview.task_state_bnt.setOnClickListener(this);
        } else {
          holderview.task_state_bnt.setTag(null);
          holderview.task_state_bnt.setOnClickListener(null);
        }
        break;
      case Task.STATE.STOP:
        holderview.history_layout.setVisibility(View.GONE);
        holderview.history_state_layout.setVisibility(View.GONE);
        holderview.remove_layout.setVisibility(View.GONE);
        holderview.task_content_layout.setVisibility(View.VISIBLE);
        holderview.taks_state_layout.setVisibility(View.VISIBLE);
        holderview.task_title.setText(meta != null ? meta.getTitle() : "");
        holderview.task_state_bnt.setBackgroundResource(
            R.drawable.ugc_ic_ioffer_upload_resume_icon);
        holderview.task_progress.setProgress(task.getTaskProgress());
        holderview.task_detail.setText(getUploadDetail(task));
        if (hasListener) {
          holderview.task_state_bnt.setTag(task);
          holderview.task_state_bnt.setOnClickListener(this);
        } else {
          holderview.task_state_bnt.setTag(null);
          holderview.task_state_bnt.setOnClickListener(null);
        }
        break;
      case Task.STATE.WAIT:
        holderview.history_layout.setVisibility(View.GONE);
        holderview.history_state_layout.setVisibility(View.GONE);
        holderview.remove_layout.setVisibility(View.GONE);
        holderview.task_content_layout.setVisibility(View.VISIBLE);
        holderview.taks_state_layout.setVisibility(View.VISIBLE);
        holderview.task_title.setText(meta != null ? meta.getTitle() : "");
        holderview.task_state_bnt.setBackgroundResource(R.drawable.ugc_ic_ioffer_upload_wait_icon);
        holderview.task_progress.setProgress(task.getTaskProgress());
        holderview.task_detail.setText(getUploadDetail(task));
        if (hasListener) {
          holderview.task_state_bnt.setTag(task);
          holderview.task_state_bnt.setOnClickListener(this);
        } else {
          holderview.task_state_bnt.setTag(null);
          holderview.task_state_bnt.setOnClickListener(null);
        }
        break;
      case Task.STATE.DONE:
        holderview.remove_layout.setVisibility(View.GONE);
        holderview.taks_state_layout.setVisibility(View.GONE);
        holderview.task_content_layout.setVisibility(View.GONE);
        holderview.history_layout.setVisibility(View.VISIBLE);
        holderview.history_state_layout.setVisibility(View.VISIBLE);
        holderview.history_title.setText(meta != null ? meta.getTitle() : "");
        holderview.history_descri.setText(task.getMetadata().getCatalogName());
        holderview.history_comment.setText("");
        holderview.history_state.setText(R.string.ugc_label_task_complete);
        holderview.task_state_bnt.setBackgroundResource(
            R.drawable.ugc_ic_ioffer_upload_resume_icon);
        updataTaskIcon(holderview, task);
        updataTaskDoneCategory(holderview, task);
        break;
    }
  }