diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..2bb2fca --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +JetpackMvvmDemo \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 7a748e4..88ea3aa 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,13 +1,6 @@ - diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 61a9130..fb7f4a8 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..ad9063f --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index db17b21..f875be7 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,9 +4,10 @@ \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 7bb9736..cf559cb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,20 @@ + + + - + diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/JetpackMvvm/build.gradle b/JetpackMvvm/build.gradle index cfa5453..dc752d6 100644 --- a/JetpackMvvm/build.gradle +++ b/JetpackMvvm/build.gradle @@ -2,16 +2,14 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' -apply plugin: 'com.github.dcendents.android-maven' -group='com.github.hegaojian' android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { minSdkVersion 21 targetSdkVersion 30 - versionCode 25 - versionName "1.2.5" + versionCode 26 + versionName "1.2.6" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles 'consumer-rules.pro' } diff --git a/JetpackMvvm/src/main/java/me/hgj/jetpackmvvm/base/fragment/BaseVmDbFragment.kt b/JetpackMvvm/src/main/java/me/hgj/jetpackmvvm/base/fragment/BaseVmDbFragment.kt index efaec8f..c320cdb 100644 --- a/JetpackMvvm/src/main/java/me/hgj/jetpackmvvm/base/fragment/BaseVmDbFragment.kt +++ b/JetpackMvvm/src/main/java/me/hgj/jetpackmvvm/base/fragment/BaseVmDbFragment.kt @@ -24,16 +24,21 @@ import me.hgj.jetpackmvvm.network.manager.NetworkStateManager abstract class BaseVmDbFragment : BaseVmFragment() { //该类绑定的ViewDataBinding - lateinit var mDatabind: DB + private var _binding: DB? = null + val mDatabind: DB get() = _binding!! override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - mDatabind = DataBindingUtil.inflate(inflater, layoutId(), container, false) + _binding = DataBindingUtil.inflate(inflater, layoutId(), container, false) mDatabind.lifecycleOwner = this return mDatabind.root } + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } } \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 9073d3e..3378c8d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "me.hgj.jetpackmvvm.demo" minSdkVersion 21 targetSdkVersion 30 - versionCode 25 - versionName "1.2.5" + versionCode 26 + versionName "1.2.6" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" /* ndk { // 设置支持的SO库架构 一般只设置这个就阔以设配所有的设备了,还可以减少apk的大小 @@ -129,9 +129,4 @@ dependencies { implementation 'me.jessyan:autosize:1.2.1' //防崩溃 implementation 'cat.ereza:customactivityoncrash:2.3.0' - //下载 - implementation("com.liulishuo.filedownloader:library:1.7.7") { - exclude group: "com.android.support" - } - implementation 'com.louiscad.splitties:splitties-collections:2.1.1' } \ No newline at end of file diff --git a/app/src/main/java/me/hgj/jetpackmvvm/demo/app/ext/download/AppDownloaderExt.kt b/app/src/main/java/me/hgj/jetpackmvvm/demo/app/ext/download/AppDownloaderExt.kt deleted file mode 100644 index 20e1d3e..0000000 --- a/app/src/main/java/me/hgj/jetpackmvvm/demo/app/ext/download/AppDownloaderExt.kt +++ /dev/null @@ -1,68 +0,0 @@ -package me.hgj.jetpackmvvm.demo.app.ext.download - -import androidx.lifecycle.MutableLiveData -import com.liulishuo.filedownloader.BaseDownloadTask -import com.liulishuo.filedownloader.FileDownloadSampleListener -import com.liulishuo.filedownloader.exception.FileDownloadOutOfSpaceException -import me.hgj.jetpackmvvm.ext.download.DownloadResultState - -/** - * @author : hgj - * @date : 2020/7/13 - * - */ - -fun BaseDownloadTask.listenerExt(downloadResultState: MutableLiveData): BaseDownloadTask { - - this.listener = object : FileDownloadSampleListener() { - override fun pending(task: BaseDownloadTask, soFarBytes: Int, totalBytes: Int) { - //开始下载 - downloadResultState.postValue(DownloadResultState.onPending()) - } - - override fun progress(task: BaseDownloadTask, soFarBytes: Int, totalBytes: Int) { - //下载中 - downloadResultState.postValue( - DownloadResultState.onProgress( - soFarBytes.toLong(), - totalBytes.toLong(), - (soFarBytes * 1.0f / totalBytes * 100).toInt() - ) - ) - } - - override fun completed(task: BaseDownloadTask) { - //下载完成 - downloadResultState.postValue( - DownloadResultState.onSuccess( - task.targetFilePath, - task.smallFileTotalBytes.toLong() - ) - ) - } - - override fun paused(task: BaseDownloadTask, soFarBytes: Int, totalBytes: Int) { - //下载暂停 - downloadResultState.postValue(DownloadResultState.onPause()) - } - - override fun error(task: BaseDownloadTask, e: Throwable) { - //下载错误 - if (task.errorCause is FileDownloadOutOfSpaceException) { - downloadResultState.postValue(DownloadResultState.onError("内存容量不足")) - } else { - downloadResultState.postValue(DownloadResultState.onError("下载出错,请重新下载")) - } - } - - override fun warn(task: BaseDownloadTask) { - //错误警告 - downloadResultState.postValue(DownloadResultState.onError("已经在下载队列中了")) - } - } - return this -} - - - - diff --git a/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/DemoFragment.kt b/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/DemoFragment.kt deleted file mode 100644 index bcf8be4..0000000 --- a/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/DemoFragment.kt +++ /dev/null @@ -1,43 +0,0 @@ -package me.hgj.jetpackmvvm.demo.ui.fragment.demo - -import android.os.Bundle -import kotlinx.android.synthetic.main.include_toolbar.* -import me.hgj.jetpackmvvm.demo.R -import me.hgj.jetpackmvvm.demo.app.base.BaseFragment -import me.hgj.jetpackmvvm.demo.app.ext.initClose -import me.hgj.jetpackmvvm.demo.databinding.FragmentDemoBinding -import me.hgj.jetpackmvvm.demo.viewmodel.state.DemoViewModel -import me.hgj.jetpackmvvm.ext.nav -import me.hgj.jetpackmvvm.ext.navigateAction - -/**放一些示例,目前只有 文件下载示例 后面想到什么加什么,作者那个比很懒,佛性添加 - * @author : hgj - * @date : 2020/7/13 - */ -class DemoFragment : BaseFragment() { - - override fun layoutId() = R.layout.fragment_demo - - override fun initView(savedInstanceState: Bundle?) { - mDatabind.click = ProxyClick() - - toolbar.initClose("示例") { - nav().navigateUp() - } - } - - - inner class ProxyClick { - fun download() { - //测试一下 普通的下载 - nav().navigateAction(R.id.action_demoFragment_to_downLoadFragment) - } - - fun downloadLibrary() { - //测试一下利用三方库下载 - nav().navigateAction(R.id.action_demoFragment_to_downLoadLibraryFragment) - } - } - - -} \ No newline at end of file diff --git a/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/DownLoadFragment.kt b/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/DownLoadFragment.kt deleted file mode 100644 index babdc56..0000000 --- a/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/DownLoadFragment.kt +++ /dev/null @@ -1,88 +0,0 @@ -package me.hgj.jetpackmvvm.demo.ui.fragment.demo - -import android.os.Bundle -import androidx.lifecycle.Observer -import com.liulishuo.filedownloader.FileDownloader -import kotlinx.android.synthetic.main.fragment_download.* -import kotlinx.android.synthetic.main.include_toolbar.* -import me.hgj.jetpackmvvm.demo.R -import me.hgj.jetpackmvvm.demo.app.base.BaseFragment -import me.hgj.jetpackmvvm.demo.app.ext.initClose -import me.hgj.jetpackmvvm.demo.app.ext.showMessage -import me.hgj.jetpackmvvm.demo.databinding.FragmentDownloadBinding -import me.hgj.jetpackmvvm.demo.viewmodel.state.DownloadViewModel -import me.hgj.jetpackmvvm.ext.download.DownloadResultState -import me.hgj.jetpackmvvm.ext.download.FileTool -import me.hgj.jetpackmvvm.ext.download.FileTool.getBasePath -import me.hgj.jetpackmvvm.ext.nav -import me.hgj.jetpackmvvm.ext.util.logd - - -/**文件下载 示例 框架自带的,功能比较简单,肯定木得三方库那么强大 - * @author : hgj - * @date : 2020/7/13 - */ -class DownLoadFragment : BaseFragment() { - - override fun layoutId() = R.layout.fragment_download - - override fun initView(savedInstanceState: Bundle?) { - mDatabind.click = ProxyClick() - toolbar.initClose("框架自带普通下载") { - nav().navigateUp() - } - } - - override fun createObserver() { - mViewModel.downloadData.observe(viewLifecycleOwner, Observer { - when (it) { - is DownloadResultState.Pending -> { - //开始下载 - "开始下载".logd() - } - is DownloadResultState.Progress -> { - //下载中 - downloadProgressBar.progress = it.progress - "下载中 ${it.soFarBytes}/${it.totalBytes}".logd() - downloadProgress.text = "${it.progress}%" - downloadSize.text ="${FileTool.bytes2kb(it.soFarBytes)}/${FileTool.bytes2kb(it.totalBytes)}" - } - is DownloadResultState.Success -> { - //下载成功 - downloadProgressBar.progress = 100 - downloadProgress.text = "100%" - downloadSize.text ="${FileTool.bytes2kb(it.totalBytes)}/${FileTool.bytes2kb(it.totalBytes)}" - showMessage("下载成功--文件地址:${it.filePath}") - } - is DownloadResultState.Pause -> { - showMessage("下载暂停") - } - is DownloadResultState.Error -> { - //下载失败 - showMessage("错误信息:${it.errorMsg}") - } - } - }) - } - - inner class ProxyClick { - fun download() { - //普通下载 - mViewModel.downloadApk( - getBasePath(), - "https://down.qq.com/qqweb/QQlite/Android_apk/qqlite_4.0.1.1060_537064364.apk", - "qq" - ) - } - - fun cancel() { - mViewModel.downloadCancel("qq") - } - - fun pause() { - mViewModel.downloadPause("qq") - } - } - - -} \ No newline at end of file diff --git a/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/DownLoadLibraryFragment.kt b/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/DownLoadLibraryFragment.kt deleted file mode 100644 index e83c24f..0000000 --- a/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/DownLoadLibraryFragment.kt +++ /dev/null @@ -1,91 +0,0 @@ -package me.hgj.jetpackmvvm.demo.ui.fragment.demo - -import android.os.Bundle -import androidx.lifecycle.Observer -import com.liulishuo.filedownloader.FileDownloader -import kotlinx.android.synthetic.main.fragment_demo.* -import kotlinx.android.synthetic.main.fragment_download.* -import kotlinx.android.synthetic.main.fragment_download_library.* -import kotlinx.android.synthetic.main.include_toolbar.* -import kotlinx.android.synthetic.main.layout_custom_progress_dialog_view.* -import me.hgj.jetpackmvvm.base.appContext -import me.hgj.jetpackmvvm.demo.R -import me.hgj.jetpackmvvm.demo.app.base.BaseFragment -import me.hgj.jetpackmvvm.demo.app.ext.initClose -import me.hgj.jetpackmvvm.demo.app.ext.showMessage -import me.hgj.jetpackmvvm.demo.databinding.FragmentDownloadLibraryBinding -import me.hgj.jetpackmvvm.demo.viewmodel.state.DownloadLibraryViewModel -import me.hgj.jetpackmvvm.ext.download.DownloadResultState -import me.hgj.jetpackmvvm.ext.download.FileTool -import me.hgj.jetpackmvvm.ext.download.FileTool.getBasePath -import me.hgj.jetpackmvvm.ext.nav -import me.hgj.jetpackmvvm.ext.util.logd - -/**集成了GitHub 高star的一个下载库 https://github.com/lingochamp/FileDownloader,供大家参考 - * @author : hgj - * @date : 2020/7/13 - */ -class DownLoadLibraryFragment : BaseFragment() { - - override fun layoutId() = R.layout.fragment_download_library - - override fun initView(savedInstanceState: Bundle?) { - mDatabind.click = ProxyClick() - //第三方下载库注册, 可以直接放在application里面注册 - FileDownloader.setup(appContext) - toolbar.initClose("三方库下载") { - nav().navigateUp() - } - } - - override fun createObserver() { - mViewModel.downloadData.observe(viewLifecycleOwner, Observer { - when (it) { - is DownloadResultState.Pending -> { - //开始下载 - "开始下载".logd() - } - is DownloadResultState.Progress -> { - //下载中 - downloadLibraryProgressBar.progress = it.progress - "下载中 ${it.soFarBytes}/${it.totalBytes}".logd() - downloadLibraryProgress.text = "${it.progress}%" - downloadLibrarySize.text = "${FileTool.bytes2kb(it.soFarBytes)}/${FileTool.bytes2kb(it.totalBytes)}" - } - is DownloadResultState.Success -> { - //下载成功 - downloadLibraryProgressBar.progress = 100 - downloadLibraryProgress.text = "100%" - downloadLibrarySize.text ="${FileTool.bytes2kb(it.totalBytes)}/${FileTool.bytes2kb(it.totalBytes)}" - showMessage("下载成功--文件地址:${it.filePath}") - } - is DownloadResultState.Pause -> { - showMessage("下载暂停") - } - is DownloadResultState.Error -> { - //下载失败 - showMessage("错误信息:${it.errorMsg}") - } - } - }) - } - - inner class ProxyClick { - fun downloadLibrary() { - //测试一下利用三方库下载 - mViewModel.downloadApkByLibrary( - getBasePath(), - "https://down.qq.com/qqweb/QQlite/Android_apk/qqlite_4.0.1.1060_537064364.apk", - "qq" - ) - } - fun cancel() { - mViewModel.downloadCancel() - } - fun pause() { - mViewModel.downloadPause() - } - } - - -} \ No newline at end of file diff --git a/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/PagerFragment.kt b/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/PagerFragment.kt deleted file mode 100644 index ac25391..0000000 --- a/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/demo/PagerFragment.kt +++ /dev/null @@ -1,51 +0,0 @@ -package me.hgj.jetpackmvvm.demo.ui.fragment.demo - -import android.os.Bundle -import androidx.fragment.app.Fragment -import androidx.fragment.app.FragmentPagerAdapter -import androidx.fragment.app.FragmentStatePagerAdapter -import kotlinx.android.synthetic.main.fragment_pager.* -import me.hgj.jetpackmvvm.demo.R -import me.hgj.jetpackmvvm.demo.app.base.BaseFragment -import me.hgj.jetpackmvvm.demo.databinding.FragmentPagerBinding -import me.hgj.jetpackmvvm.demo.ui.fragment.collect.CollectFragment -import me.hgj.jetpackmvvm.demo.ui.fragment.search.SearchFragment -import me.hgj.jetpackmvvm.demo.ui.fragment.share.AriticleFragment -import me.hgj.jetpackmvvm.demo.ui.fragment.todo.TodoListFragment -import me.hgj.jetpackmvvm.demo.viewmodel.state.MainViewModel - -/** - * @author : hgj - * @date : 2020/6/15 - * 测试 Viewpager下的懒加载 - */ -class PagerFragment : BaseFragment() { - - override fun layoutId() = R.layout.fragment_pager - - override fun initView(savedInstanceState: Bundle?) { - pagerViewpager.adapter = object : FragmentStatePagerAdapter(childFragmentManager,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { - override fun getItem(position: Int): Fragment { - return when (position) { - 0 -> { - SearchFragment() - } - 1 -> { - TodoListFragment() - } - 2 -> { - AriticleFragment() - } - else -> { - CollectFragment() - } - } - } - - override fun getCount(): Int { - return 5; - } - } - pagerViewpager.offscreenPageLimit = 5 - } -} \ No newline at end of file diff --git a/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/me/MeFragment.kt b/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/me/MeFragment.kt index ae7cda8..bb84f92 100644 --- a/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/me/MeFragment.kt +++ b/app/src/main/java/me/hgj/jetpackmvvm/demo/ui/fragment/me/MeFragment.kt @@ -145,10 +145,5 @@ class MeFragment : BaseFragment() { nav().navigateAction(R.id.action_mainfragment_to_settingFragment) } - /**demo*/ - fun demo() { - nav().navigateAction(R.id.action_to_demoFragment) - } - } } \ No newline at end of file diff --git a/app/src/main/java/me/hgj/jetpackmvvm/demo/viewmodel/request/RequestLoginRegisterViewModel.kt b/app/src/main/java/me/hgj/jetpackmvvm/demo/viewmodel/request/RequestLoginRegisterViewModel.kt index 09f803f..73bd472 100644 --- a/app/src/main/java/me/hgj/jetpackmvvm/demo/viewmodel/request/RequestLoginRegisterViewModel.kt +++ b/app/src/main/java/me/hgj/jetpackmvvm/demo/viewmodel/request/RequestLoginRegisterViewModel.kt @@ -23,21 +23,21 @@ class RequestLoginRegisterViewModel : BaseViewModel() { fun loginReq(username: String, password: String) { //1.这种是在 Activity/Fragment的监听回调中拿到已脱壳的数据(项目有基类的可以用) - request( + /* request( { apiService.login(username, password) }//请求体 , loginResult,//请求的返回结果,请求成功与否都会改变该值,在Activity或fragment中监听回调结果,具体可看loginActivity中的回调 true,//是否显示等待框,,默认false不显示 可以默认不传 "正在登录中..."//等待框内容,可以默认不填请求网络中... - ) + )*/ //2.这种是在Activity/Fragment中的监听拿到未脱壳的数据,你可以自己根据code做业务需求操作(项目没有基类的可以用) /*requestNoCheck({HttpRequestCoroutine.login(username,password)},loginResult2,true)*/ //3. 这种是直接在当前ViewModel中就拿到了脱壳数据数据,做一层封装再给Activity/Fragment,如果 (项目有基类的可以用) - /* request({HttpRequestCoroutine.login(username,password)},{ + request({apiService.login(username, password)},{ //请求成功 已自动处理了 请求结果是否正常 },{ //请求失败 网络异常,或者请求结果码错误都会回调在这里 - })*/ + }) //4.这种是直接在当前ViewModel中就拿到了未脱壳数据数据,(项目没有基类的可以用) /*requestNoCheck({HttpRequestCoroutine.login(username,password)},{ diff --git a/app/src/main/java/me/hgj/jetpackmvvm/demo/viewmodel/state/DownloadLibraryViewModel.kt b/app/src/main/java/me/hgj/jetpackmvvm/demo/viewmodel/state/DownloadLibraryViewModel.kt deleted file mode 100644 index 84b032a..0000000 --- a/app/src/main/java/me/hgj/jetpackmvvm/demo/viewmodel/state/DownloadLibraryViewModel.kt +++ /dev/null @@ -1,62 +0,0 @@ -package me.hgj.jetpackmvvm.demo.viewmodel.state - -import androidx.lifecycle.MutableLiveData -import com.liulishuo.filedownloader.BaseDownloadTask -import com.liulishuo.filedownloader.FileDownloader -import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel -import me.hgj.jetpackmvvm.demo.app.ext.download.listenerExt -import me.hgj.jetpackmvvm.ext.download.DownloadResultState - -/** - * @author : hgj - * @date : 2020/7/14 - */ -class DownloadLibraryViewModel : BaseViewModel() { - var downloadData: MutableLiveData = MutableLiveData() - - private var baseDownloadTask: BaseDownloadTask? = null - - private val fileDownloader by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { - FileDownloader.getImpl() - } - - /** - * Apk三方库下载 - * @param path String 保存路径 - * @param url String 下载路径 - * @param tag Any 下载标识 - */ - fun downloadApkByLibrary(path: String, url: String, tag: Any) { - baseDownloadTask = fileDownloader.create(url) - baseDownloadTask?.let { - it.setPath("$path/cxk_tmd.apk", false) - .setAutoRetryTimes(5) - //是否直接强制下载,不管文件是否存在,如果想每次都下载那就设置为true吧 - .setForceReDownload(false) - .setCallbackProgressTimes(300) - .setMinIntervalUpdateSpeed(400) - .tag = tag - it.listenerExt(downloadData) - .start() - } - } - - /** - * Apk取消下载 - */ - fun downloadCancel() { - baseDownloadTask?.let { fileDownloader.clear(it.id, it.targetFilePath) } - } - - /** - * Apk暂停下载 - */ - fun downloadPause() { - baseDownloadTask?.let { fileDownloader.pause(it.id) } - } - - override fun onCleared() { - super.onCleared() - } - -} \ No newline at end of file diff --git a/app/src/main/java/me/hgj/jetpackmvvm/demo/viewmodel/state/DownloadViewModel.kt b/app/src/main/java/me/hgj/jetpackmvvm/demo/viewmodel/state/DownloadViewModel.kt deleted file mode 100644 index f53b7c5..0000000 --- a/app/src/main/java/me/hgj/jetpackmvvm/demo/viewmodel/state/DownloadViewModel.kt +++ /dev/null @@ -1,49 +0,0 @@ -package me.hgj.jetpackmvvm.demo.viewmodel.state - -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.viewModelScope -import kotlinx.coroutines.launch -import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel -import me.hgj.jetpackmvvm.ext.download.DownLoadManager -import me.hgj.jetpackmvvm.ext.download.DownloadResultState -import me.hgj.jetpackmvvm.ext.download.downLoadExt - -/** - * @author : hgj - * @date : 2020/7/14 - */ - -class DownloadViewModel : BaseViewModel() { - - var downloadData: MutableLiveData = MutableLiveData() - - /** - * Apk普通下载 框架自带 - * @param path String 文件保存路径 - * @param url String 文件下载url - * @param tag String 下载标识,根据该值可取消,暂停 - */ - fun downloadApk(path: String, url: String, tag: String) { - viewModelScope.launch { - //直接强制下载,不管文件是否存在 ,如果需要每次都重新下载可以设置为true - DownLoadManager.downLoad(tag, url, path, "tmd.apk", false, downLoadExt(downloadData)) - } - } - - /** - * 取消下载 - * @param tag String - */ - fun downloadCancel(tag: String) { - DownLoadManager.cancel(tag) - } - - /** - * Apk暂停下载 - * @param tag String - */ - fun downloadPause(tag: String) { - DownLoadManager.pause(tag) - } - -} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_demo.xml b/app/src/main/res/layout/fragment_demo.xml deleted file mode 100644 index 9a79c04..0000000 --- a/app/src/main/res/layout/fragment_demo.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_download.xml b/app/src/main/res/layout/fragment_download.xml deleted file mode 100644 index 3a3d2f3..0000000 --- a/app/src/main/res/layout/fragment_download.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - - - - - - - - - - - - -