-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.下载文件增加缓存机制(如果本地已经有文件了,直接使用本地文件,反之才远程下载文件)
- Loading branch information
tli2
committed
Nov 20, 2020
1 parent
6be1baa
commit 126b8c9
Showing
26 changed files
with
295 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
app/src/main/java/com/catchpig/kotlin_mvp/di/MainModule.kt
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/catchpig/kotlin_mvp/di/ScopeModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.catchpig.kotlin_mvp.di | ||
|
||
import com.catchpig.kotlin_mvp.mvp.apk.InstallApkContract | ||
import com.catchpig.kotlin_mvp.mvp.apk.model.InstallApkModel | ||
import com.catchpig.kotlin_mvp.mvp.apk.presenter.InstallApkPresenter | ||
import com.catchpig.kotlin_mvp.mvp.apk.view.InstallApkActivity | ||
import com.catchpig.kotlin_mvp.mvp.main.MainContract | ||
import com.catchpig.kotlin_mvp.mvp.main.model.MainModel | ||
import com.catchpig.kotlin_mvp.mvp.main.presenter.MainPresenter | ||
import com.catchpig.kotlin_mvp.mvp.main.view.MainActivity | ||
import org.koin.core.qualifier.named | ||
import org.koin.dsl.bind | ||
import org.koin.dsl.module | ||
|
||
/** | ||
* @author catchpig | ||
* @date 2019/8/18 00:18 | ||
*/ | ||
val scopeModule = module { | ||
scope<MainActivity> { | ||
scoped { (view:MainContract.View)-> | ||
MainPresenter(view,get()) | ||
} bind MainContract.Presenter::class | ||
|
||
scoped { | ||
MainModel(get()) | ||
} bind MainContract.Model::class | ||
} | ||
|
||
scope<InstallApkActivity> { | ||
scoped { (view:InstallApkContract.View)-> | ||
InstallApkPresenter(view, get()) | ||
} bind InstallApkContract.Presenter::class | ||
|
||
scoped { | ||
InstallApkModel(get()) | ||
} bind InstallApkContract.Model::class | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/catchpig/kotlin_mvp/mvp/apk/InstallApkContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.catchpig.kotlin_mvp.mvp.apk | ||
|
||
import com.catchpig.mvp.base.BaseContract | ||
import com.catchpig.mvp.bean.DownloadInfo | ||
import com.catchpig.mvp.network.listener.DownloadCallback | ||
|
||
/** | ||
* | ||
* @author catchpig | ||
* @date 2020/11/20 15:52 | ||
*/ | ||
interface InstallApkContract { | ||
interface View:BaseContract.View{ | ||
/** | ||
* 设置进度 | ||
* @param progress Int | ||
*/ | ||
fun setDownloadProgress(progress:Int) | ||
} | ||
interface Presenter:BaseContract.Presenter{ | ||
fun download() | ||
} | ||
interface Model{ | ||
/** | ||
* 下载 | ||
* @param downloadInfo DownloadInfo | ||
* @param downloadCallback DownloadCallback | ||
*/ | ||
fun download(downloadInfo: DownloadInfo, downloadCallback: DownloadCallback) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/catchpig/kotlin_mvp/mvp/apk/model/InstallApkModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.catchpig.kotlin_mvp.mvp.apk.model | ||
|
||
import com.catchpig.kotlin_mvp.mvp.apk.InstallApkContract | ||
import com.catchpig.mvp.bean.DownloadInfo | ||
import com.catchpig.mvp.network.download.DownloadManager | ||
import com.catchpig.mvp.network.listener.DownloadCallback | ||
|
||
/** | ||
* | ||
* @author catchpig | ||
* @date 2020/11/20 15:51 | ||
*/ | ||
class InstallApkModel(private val downloadManager: DownloadManager):InstallApkContract.Model { | ||
override fun download(downloadInfo: DownloadInfo, downloadCallback: DownloadCallback) { | ||
downloadManager.download(downloadInfo,downloadCallback) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/catchpig/kotlin_mvp/mvp/apk/presenter/InstallApkPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.catchpig.kotlin_mvp.mvp.apk.presenter | ||
|
||
import com.catchpig.kotlin_mvp.mvp.apk.InstallApkContract | ||
import com.catchpig.mvp.base.BasePresenter | ||
import com.catchpig.mvp.bean.DownloadInfo | ||
import com.catchpig.mvp.network.listener.DownloadCallback | ||
import com.catchpig.utils.ext.installApk | ||
|
||
/** | ||
* | ||
* @author catchpig | ||
* @date 2020/11/20 15:51 | ||
*/ | ||
class InstallApkPresenter(private val view: InstallApkContract.View,private val model: InstallApkContract.Model):BasePresenter(),InstallApkContract.Presenter{ | ||
override fun download() { | ||
val downloadInfo = DownloadInfo("https://wanandroid.com/","blogimgs/2d120094-e1ee-47fb-a155-6eb4ca49d01f.apk") | ||
model.download(downloadInfo,object : DownloadCallback { | ||
override fun onStart() { | ||
|
||
} | ||
|
||
override fun onSuccess(path: String) { | ||
view.activity().installApk(path) | ||
} | ||
|
||
override fun onComplete() { | ||
} | ||
|
||
override fun onProgress(readLength: Long, countLength: Long) { | ||
view.setDownloadProgress((readLength*100/countLength).toInt()) | ||
} | ||
|
||
override fun onError(t: Throwable) { | ||
println(t.message) | ||
} | ||
}) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/catchpig/kotlin_mvp/mvp/apk/view/InstallApkActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.catchpig.kotlin_mvp.mvp.apk.view | ||
|
||
import android.Manifest | ||
import com.catchpig.annotation.Title | ||
import com.catchpig.kotlin_mvp.R | ||
import com.catchpig.kotlin_mvp.mvp.apk.InstallApkContract | ||
import com.catchpig.mvp.base.activity.BasePresenterActivity | ||
import com.tbruyelle.rxpermissions2.RxPermissions | ||
import kotlinx.android.synthetic.main.activity_install_apk.* | ||
import org.koin.core.parameter.parametersOf | ||
import org.koin.core.scope.inject | ||
|
||
/** | ||
* | ||
* @author catchpig | ||
* @date 2020/11/20 15:50 | ||
*/ | ||
@Title(R.string.download_install_apk) | ||
class InstallApkActivity:BasePresenterActivity<InstallApkContract.Presenter>(),InstallApkContract.View { | ||
override val mPresenter: InstallApkContract.Presenter by inject{ parametersOf(this) } | ||
private val rxPermissions by lazy { RxPermissions(this) } | ||
override fun initParam() { | ||
|
||
} | ||
|
||
override fun initView() { | ||
rxPermissions | ||
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||
.subscribe { | ||
if (it) { | ||
mPresenter.download() | ||
} | ||
} | ||
} | ||
|
||
override fun layoutId(): Int { | ||
return R.layout.activity_install_apk | ||
} | ||
|
||
override fun setDownloadProgress(progress: Int) { | ||
progressBar.progress = progress | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/catchpig/kotlin_mvp/mvp/transparent/TransparentActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center"> | ||
<ProgressBar | ||
android:id="@+id/progressBar" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp" | ||
android:layout_margin="10dp" | ||
style="?android:attr/progressBarStyleHorizontal" | ||
android:max="100"/> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.