Rely first
Compile ' com.liulishuo.filedownloader:library:1.3.0 '
ImportAndroid.content.Context;ImportCom.hyphenate.chat.EMMessage;ImportCom.liulishuo.filedownloader.BaseDownloadTask;ImportCom.liulishuo.filedownloader.FileDownloadListener;ImportCom.liulishuo.filedownloader.FileDownloader;ImportCom.xuehu365.xuehu.data.DynamicDownLoadData;ImportCom.xuehu365.xuehu.model.DynamicModel;Importcom.xuehu365.xuehu.model.event.DynamicDownLoadProgress;ImportCom.xuehu365.xuehu.utils.PathUtil;ImportOrg.greenrobot.eventbus.EventBus;ImportJava.io.File;/*** Created by Administrator on 2017/1/13.*/ Public classDynamicdownloader { Public Static voidDownLoad (Context context,FinalDynamicmodel Dynamicmodel) {String FileName= Dynamicmodel.getlinkurl (). substring (Dynamicmodel.getlinkurl (). LastIndexOf ("/") + 1); String FilePath= Pathutil.getinstance (). Getvideopath () + File.separator +FileName; Basedownloadtask Task=Filedownloader.getimpl (). Create (Dynamicmodel.getlinkurl ()). SetPath (FilePath). Setlistener (NewFiledownloadlistener () {@Overrideprotected voidPending (Basedownloadtask task,intSofarbytes,inttotalbytes) {} @Overrideprotected voidProgress (Basedownloadtask task,intSofarbytes,inttotalbytes) {dynamicmodel.setdownloadpercent (Math.Round ((float) (Sofarbytes * 100))/totalbytes)); Dynamicmodel.setdownloadstatus (EMMessage.Status.INPROGRESS.ordinal ()); Dynamicdownloaddata.saveview (Dynamicmodel); Eventbus.getdefault (). Post (Newdynamicdownloadprogress ()); } @Overrideprotected voidcompleted (basedownloadtask Task) {Dynamicmodel.setloadlurl (Task.getpath ()); Dynamicmodel.setdownloadstatus (EMMessage.Status.SUCCESS.ordinal ()); Dynamicdownloaddata.saveview (Dynamicmodel); Eventbus.getdefault (). Post (Newdynamicdownloadprogress ()); } @Overrideprotected voidPaused (basedownloadtask task,intSofarbytes,inttotalbytes) {} @Overrideprotected voidError (basedownloadtask task, Throwable e) {dynamicmodel.setdownloadstatus (EMMessage.Status.FA Il.ordinal ()); Dynamicdownloaddata.saveview (Dynamicmodel); Eventbus.getdefault (). Post (Newdynamicdownloadprogress ()); } @Overrideprotected voidwarn (basedownloadtask Task) {}}); Task.start (); }}
File Download Tool class