Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.timurmuhortov.multithread_downloader.presentation.presenter
- import android.webkit.URLUtil
- import com.example.timurmuhortov.multithread_downloader.ui.MainActivity
- import com.example.timurmuhortov.multithread_downloader.utils.AsyncResponse
- import com.example.timurmuhortov.multithread_downloader.utils.MakeRequestTask
- /**
- * @author: timur.mukhortov
- * date: 05.02.2018
- * time: 22:40
- * @LinkedIn: linkedin.com/in/timurmukhortov
- **/
- class MainPresenter : AsyncResponse {
- private var view: MainActivity? = null
- fun paramsRequest(url: String, countThread: Int) {
- if (checkURL(url)) {
- MakeRequestTask(this).execute(url, countThread.toString())
- }
- }
- fun attachView(mainActivity: MainActivity) {
- this.view = mainActivity
- }
- fun detachView() {
- this.view = null
- }
- private fun checkURL(url: String): Boolean {
- if (url.isEmpty()) {
- view.createAlertDialog("Введите URL!")
- return false
- }
- if (!URLUtil.isNetworkUrl(url)) {
- view.createAlertDialog("Некоректная URL ссылка.")
- return false
- }
- return true
- }
- override fun responseServer(responseRequest: String) {
- view.createAlertDialog(responseRequest)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement