parent
							
								
									3b30d31b8e
								
							
						
					
					
						commit
						ac99cc581f
					
				@ -0,0 +1,103 @@ | 
				
			|||||||
 | 
					/* | 
				
			||||||
 | 
					 * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
 | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * Licensed under the Apache License, Version 2.0 (the "License"); | 
				
			||||||
 | 
					 * you may not use this file except in compliance with the License. | 
				
			||||||
 | 
					 * You may obtain a copy of the License at | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 *      http://www.apache.org/licenses/LICENSE-2.0
 | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * Unless required by applicable law or agreed to in writing, software | 
				
			||||||
 | 
					 * distributed under the License is distributed on an "AS IS" BASIS, | 
				
			||||||
 | 
					 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
				
			||||||
 | 
					 * See the License for the specific language governing permissions and | 
				
			||||||
 | 
					 * limitations under the License. | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					package com.arialyy.aria.core; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.text.TextUtils; | 
				
			||||||
 | 
					import android.util.Log; | 
				
			||||||
 | 
					import com.arialyy.aria.core.command.group.GroupCmdFactory; | 
				
			||||||
 | 
					import com.arialyy.aria.core.inf.BaseGroupTaskEntity; | 
				
			||||||
 | 
					import com.arialyy.aria.util.CommonUtil; | 
				
			||||||
 | 
					import java.util.List; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Created by lyy on 2017/9/4. | 
				
			||||||
 | 
					 * 子任务管理器 | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public class SubTaskManager { | 
				
			||||||
 | 
					  private String TAG = "SubTaskManager"; | 
				
			||||||
 | 
					  private BaseGroupTaskEntity mEntity; | 
				
			||||||
 | 
					  private String mTargetName; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public SubTaskManager(String targetName, BaseGroupTaskEntity entity) { | 
				
			||||||
 | 
					    mTargetName = targetName; | 
				
			||||||
 | 
					    mEntity = entity; | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /** | 
				
			||||||
 | 
					   * 启动任务组中的子任务 | 
				
			||||||
 | 
					   * | 
				
			||||||
 | 
					   * @param url 子任务下载地址 | 
				
			||||||
 | 
					   */ | 
				
			||||||
 | 
					  public void startSubTask(String url) { | 
				
			||||||
 | 
					    if (checkUrl(url)) { | 
				
			||||||
 | 
					      AriaManager.getInstance(AriaManager.APP) | 
				
			||||||
 | 
					          .setCmd( | 
				
			||||||
 | 
					              CommonUtil.createGroupCmd(mTargetName, mEntity, GroupCmdFactory.SUB_TASK_START, url)) | 
				
			||||||
 | 
					          .exe(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /** | 
				
			||||||
 | 
					   * 停止任务组中的子任务 | 
				
			||||||
 | 
					   * | 
				
			||||||
 | 
					   * @param url 子任务下载地址 | 
				
			||||||
 | 
					   */ | 
				
			||||||
 | 
					  public void stopSubTask(String url) { | 
				
			||||||
 | 
					    if (checkUrl(url)) { | 
				
			||||||
 | 
					      AriaManager.getInstance(AriaManager.APP) | 
				
			||||||
 | 
					          .setCmd( | 
				
			||||||
 | 
					              CommonUtil.createGroupCmd(mTargetName, mEntity, GroupCmdFactory.SUB_TASK_STOP, url)) | 
				
			||||||
 | 
					          .exe(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /** | 
				
			||||||
 | 
					   * 删除子任务组中的子任务 | 
				
			||||||
 | 
					   * | 
				
			||||||
 | 
					   * @param url 子任务下载地址 | 
				
			||||||
 | 
					   */ | 
				
			||||||
 | 
					  public void cancelSubTask(String url) { | 
				
			||||||
 | 
					    if (checkUrl(url)) { | 
				
			||||||
 | 
					      AriaManager.getInstance(AriaManager.APP) | 
				
			||||||
 | 
					          .setCmd( | 
				
			||||||
 | 
					              CommonUtil.createGroupCmd(mTargetName, mEntity, GroupCmdFactory.SUB_TASK_CANCEL, url)) | 
				
			||||||
 | 
					          .exe(); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /** | 
				
			||||||
 | 
					   * 检查任务地址 | 
				
			||||||
 | 
					   * | 
				
			||||||
 | 
					   * @param url 子任务地址 | 
				
			||||||
 | 
					   * @return {@code false} 任务地址不合法 | 
				
			||||||
 | 
					   */ | 
				
			||||||
 | 
					  private boolean checkUrl(String url) { | 
				
			||||||
 | 
					    if (TextUtils.isEmpty(url)) { | 
				
			||||||
 | 
					      Log.e(TAG, "子任务地址不能为null"); | 
				
			||||||
 | 
					      return false; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					    List<String> urls = mEntity.getEntity().getUrls(); | 
				
			||||||
 | 
					    if (urls == null || urls.isEmpty()) { | 
				
			||||||
 | 
					      Log.e(TAG, "任务组任务链接为null"); | 
				
			||||||
 | 
					      return false; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					    if (!urls.contains(url)) { | 
				
			||||||
 | 
					      Log.e(TAG, "任务组中没有改Url【+ " + url + "】"); | 
				
			||||||
 | 
					      return false; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					    return true; | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,26 @@ | 
				
			|||||||
 | 
					/* | 
				
			||||||
 | 
					 * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
 | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * Licensed under the Apache License, Version 2.0 (the "License"); | 
				
			||||||
 | 
					 * you may not use this file except in compliance with the License. | 
				
			||||||
 | 
					 * You may obtain a copy of the License at | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 *      http://www.apache.org/licenses/LICENSE-2.0
 | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * Unless required by applicable law or agreed to in writing, software | 
				
			||||||
 | 
					 * distributed under the License is distributed on an "AS IS" BASIS, | 
				
			||||||
 | 
					 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
				
			||||||
 | 
					 * See the License for the specific language governing permissions and | 
				
			||||||
 | 
					 * limitations under the License. | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package com.arialyy.aria.core.inf; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Created by lyy on 2017/9/5. | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public abstract class BaseGroupTaskEntity<ENTITY extends AbsGroupEntity> extends AbsTaskEntity<ENTITY>{ | 
				
			||||||
 | 
					  @Override public ENTITY getEntity() { | 
				
			||||||
 | 
					    return null; | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,123 @@ | 
				
			|||||||
 | 
					/* | 
				
			||||||
 | 
					 * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
 | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * Licensed under the Apache License, Version 2.0 (the "License"); | 
				
			||||||
 | 
					 * you may not use this file except in compliance with the License. | 
				
			||||||
 | 
					 * You may obtain a copy of the License at | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 *      http://www.apache.org/licenses/LICENSE-2.0
 | 
				
			||||||
 | 
					 * | 
				
			||||||
 | 
					 * Unless required by applicable law or agreed to in writing, software | 
				
			||||||
 | 
					 * distributed under the License is distributed on an "AS IS" BASIS, | 
				
			||||||
 | 
					 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
				
			||||||
 | 
					 * See the License for the specific language governing permissions and | 
				
			||||||
 | 
					 * limitations under the License. | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					package com.arialyy.simple.download.group; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.annotation.SuppressLint; | 
				
			||||||
 | 
					import android.content.Context; | 
				
			||||||
 | 
					import android.os.Bundle; | 
				
			||||||
 | 
					import android.util.Log; | 
				
			||||||
 | 
					import android.view.Gravity; | 
				
			||||||
 | 
					import android.view.View; | 
				
			||||||
 | 
					import android.view.ViewGroup; | 
				
			||||||
 | 
					import android.view.Window; | 
				
			||||||
 | 
					import android.view.WindowManager; | 
				
			||||||
 | 
					import android.widget.TextView; | 
				
			||||||
 | 
					import butterknife.Bind; | 
				
			||||||
 | 
					import butterknife.OnClick; | 
				
			||||||
 | 
					import com.arialyy.annotations.DownloadGroup; | 
				
			||||||
 | 
					import com.arialyy.aria.core.Aria; | 
				
			||||||
 | 
					import com.arialyy.aria.core.download.DownloadEntity; | 
				
			||||||
 | 
					import com.arialyy.aria.core.download.DownloadGroupTask; | 
				
			||||||
 | 
					import com.arialyy.simple.R; | 
				
			||||||
 | 
					import com.arialyy.simple.base.BaseDialog; | 
				
			||||||
 | 
					import com.arialyy.simple.databinding.DialogSubTaskHandlerBinding; | 
				
			||||||
 | 
					import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; | 
				
			||||||
 | 
					import java.util.List; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Created by Aria.Lao on 2017/9/5. | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					@SuppressLint("ValidFragment") public class ChildHandleDialog | 
				
			||||||
 | 
					    extends BaseDialog<DialogSubTaskHandlerBinding> { | 
				
			||||||
 | 
					  @Bind(R.id.sub_task) TextView mSub; | 
				
			||||||
 | 
					  @Bind(R.id.task_group) TextView mGroup; | 
				
			||||||
 | 
					  @Bind(R.id.pb) HorizontalProgressBarWithNumber mPb; | 
				
			||||||
 | 
					  private String mGroupName; | 
				
			||||||
 | 
					  private String mChildName; | 
				
			||||||
 | 
					  private DownloadEntity mChildEntity; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public ChildHandleDialog(Context context, String groupAliaName, DownloadEntity childEntity) { | 
				
			||||||
 | 
					    super(context); | 
				
			||||||
 | 
					    setStyle(STYLE_NO_TITLE, R.style.Theme_Light_Dialog); | 
				
			||||||
 | 
					    mChildEntity = childEntity; | 
				
			||||||
 | 
					    mGroupName = groupAliaName; | 
				
			||||||
 | 
					    mChildName = childEntity.getFileName(); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Override protected void init(Bundle savedInstanceState) { | 
				
			||||||
 | 
					    super.init(savedInstanceState); | 
				
			||||||
 | 
					    Aria.download(this).register(); | 
				
			||||||
 | 
					    initWidget(); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Override public void onDestroy() { | 
				
			||||||
 | 
					    super.onDestroy(); | 
				
			||||||
 | 
					    Aria.download(this).unRegister(); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private void initWidget() { | 
				
			||||||
 | 
					    mGroup.setText("任务组:" + mGroupName); | 
				
			||||||
 | 
					    mSub.setText("子任务:" + mChildName); | 
				
			||||||
 | 
					    mPb.setProgress((int) (mChildEntity.getCurrentProgress() * 100 / mChildEntity.getFileSize())); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Window window = getDialog().getWindow(); | 
				
			||||||
 | 
					    window.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); | 
				
			||||||
 | 
					    WindowManager.LayoutParams p = window.getAttributes(); | 
				
			||||||
 | 
					    p.width = ViewGroup.LayoutParams.MATCH_PARENT; | 
				
			||||||
 | 
					    window.setAttributes(p); | 
				
			||||||
 | 
					    window.setWindowAnimations(R.style.dialogStyle); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @DownloadGroup.onTaskResume void onTaskResume(DownloadGroupTask task) { | 
				
			||||||
 | 
					    mSub.setText("子任务:" + mChildName + ",状态:下载中"); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @DownloadGroup.onTaskCancel void onTaskCancel(DownloadGroupTask task) { | 
				
			||||||
 | 
					    mSub.setText("子任务:" + mChildName + ",状态:取消下载"); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @DownloadGroup.onTaskRunning void onTaskRunning(DownloadGroupTask task) { | 
				
			||||||
 | 
					    mPb.setProgress((int) (mChildEntity.getCurrentProgress() * 100 / mChildEntity.getFileSize())); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @DownloadGroup.onTaskStop void onTaskStop(DownloadGroupTask task) { | 
				
			||||||
 | 
					    mSub.setText("子任务:" + mChildName + ",状态:任务停止"); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @DownloadGroup.onTaskComplete void onTaskComplete(DownloadGroupTask task) { | 
				
			||||||
 | 
					    mSub.setText("子任务:" + mChildName + ",状态:任务完成"); | 
				
			||||||
 | 
					    mPb.setProgress(100); | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Override protected int setLayoutId() { | 
				
			||||||
 | 
					    return R.layout.dialog_sub_task_handler; | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @OnClick({ R.id.start, R.id.stop, R.id.cancel }) void onClick(View view) { | 
				
			||||||
 | 
					    switch (view.getId()) { | 
				
			||||||
 | 
					      case R.id.start: | 
				
			||||||
 | 
					        break; | 
				
			||||||
 | 
					      case R.id.stop: | 
				
			||||||
 | 
					        break; | 
				
			||||||
 | 
					      case R.id.cancel: | 
				
			||||||
 | 
					        break; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Override protected void dataCallback(int result, Object obj) { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,5 @@ | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="utf-8"?> | 
				
			||||||
 | 
					<set xmlns:android="http://schemas.android.com/apk/res/android"> | 
				
			||||||
 | 
					  <translate android:fromYDelta="100%" | 
				
			||||||
 | 
					      android:duration="100"/> | 
				
			||||||
 | 
					</set> | 
				
			||||||
@ -0,0 +1,6 @@ | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="utf-8"?> | 
				
			||||||
 | 
					<set xmlns:android="http://schemas.android.com/apk/res/android"> | 
				
			||||||
 | 
					  <translate | 
				
			||||||
 | 
					      android:duration="100" | 
				
			||||||
 | 
					      android:toYDelta="100%"/> | 
				
			||||||
 | 
					</set> | 
				
			||||||
@ -0,0 +1,76 @@ | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="utf-8"?> | 
				
			||||||
 | 
					<layout xmlns:android="http://schemas.android.com/apk/res/android" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    > | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <RelativeLayout | 
				
			||||||
 | 
					      android:layout_width="match_parent" | 
				
			||||||
 | 
					      android:layout_height="wrap_content" | 
				
			||||||
 | 
					      android:background="@color/white" | 
				
			||||||
 | 
					      android:padding="16dp" | 
				
			||||||
 | 
					      > | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <TextView | 
				
			||||||
 | 
					        android:id="@+id/task_group" | 
				
			||||||
 | 
					        android:layout_width="wrap_content" | 
				
			||||||
 | 
					        android:layout_height="wrap_content" | 
				
			||||||
 | 
					        android:text="任务组:" | 
				
			||||||
 | 
					        /> | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <TextView | 
				
			||||||
 | 
					        android:id="@+id/sub_task" | 
				
			||||||
 | 
					        android:layout_width="wrap_content" | 
				
			||||||
 | 
					        android:layout_height="wrap_content" | 
				
			||||||
 | 
					        android:layout_below="@+id/task_group" | 
				
			||||||
 | 
					        android:layout_marginTop="5dp" | 
				
			||||||
 | 
					        android:text="子任务:" | 
				
			||||||
 | 
					        /> | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <com.arialyy.simple.widget.HorizontalProgressBarWithNumber | 
				
			||||||
 | 
					        android:id="@+id/pb" | 
				
			||||||
 | 
					        android:layout_width="match_parent" | 
				
			||||||
 | 
					        android:layout_height="wrap_content" | 
				
			||||||
 | 
					        android:layout_below="@+id/sub_task" | 
				
			||||||
 | 
					        android:layout_marginTop="10dp" | 
				
			||||||
 | 
					        android:max="100" | 
				
			||||||
 | 
					        /> | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <LinearLayout | 
				
			||||||
 | 
					        android:layout_width="match_parent" | 
				
			||||||
 | 
					        android:layout_height="wrap_content" | 
				
			||||||
 | 
					        android:layout_below="@+id/pb" | 
				
			||||||
 | 
					        android:orientation="horizontal" | 
				
			||||||
 | 
					        > | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <Button | 
				
			||||||
 | 
					          android:id="@+id/start" | 
				
			||||||
 | 
					          android:layout_width="wrap_content" | 
				
			||||||
 | 
					          android:layout_height="wrap_content" | 
				
			||||||
 | 
					          android:layout_weight="1" | 
				
			||||||
 | 
					          android:text="开始" | 
				
			||||||
 | 
					          style="?buttonBarButtonStyle" | 
				
			||||||
 | 
					          /> | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <Button | 
				
			||||||
 | 
					          android:id="@+id/stop" | 
				
			||||||
 | 
					          android:layout_width="wrap_content" | 
				
			||||||
 | 
					          android:layout_height="wrap_content" | 
				
			||||||
 | 
					          android:layout_weight="1" | 
				
			||||||
 | 
					          android:text="停止" | 
				
			||||||
 | 
					          style="?buttonBarButtonStyle" | 
				
			||||||
 | 
					          /> | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <Button | 
				
			||||||
 | 
					          android:id="@+id/cancel" | 
				
			||||||
 | 
					          android:layout_width="wrap_content" | 
				
			||||||
 | 
					          android:layout_height="wrap_content" | 
				
			||||||
 | 
					          android:layout_weight="1" | 
				
			||||||
 | 
					          android:text="删除" | 
				
			||||||
 | 
					          style="?buttonBarButtonStyle" | 
				
			||||||
 | 
					          /> | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    </LinearLayout> | 
				
			||||||
 | 
					  </RelativeLayout> | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</layout> | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue