Advertisement
elsemTim

Untitled

Feb 6th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.35 KB | None | 0 0
  1. package com.example.timurmuhortov.multithread_downloader.presentation.presenter
  2.  
  3. import android.webkit.URLUtil
  4. import com.example.timurmuhortov.multithread_downloader.ui.MainActivity
  5. import com.example.timurmuhortov.multithread_downloader.utils.AsyncResponse
  6. import com.example.timurmuhortov.multithread_downloader.utils.MakeRequestTask
  7.  
  8. /**
  9.  * @author: timur.mukhortov
  10.  * date: 05.02.2018
  11.  * time: 22:40
  12.  * @LinkedIn: linkedin.com/in/timurmukhortov
  13.  **/
  14.  
  15.  
  16. class MainPresenter : AsyncResponse {
  17.  
  18.     private var view: MainActivity? = null
  19.  
  20.     fun paramsRequest(url: String, countThread: Int) {
  21.         if (checkURL(url)) {
  22.             MakeRequestTask(this).execute(url, countThread.toString())
  23.         }
  24.     }
  25.  
  26.     fun attachView(mainActivity: MainActivity) {
  27.         this.view = mainActivity
  28.     }
  29.  
  30.     fun detachView() {
  31.         this.view = null
  32.     }
  33.  
  34.     private fun checkURL(url: String): Boolean {
  35.  
  36.         if (url.isEmpty()) {
  37.             view.createAlertDialog("Введите URL!")
  38.             return false
  39.         }
  40.  
  41.         if (!URLUtil.isNetworkUrl(url)) {
  42.             view.createAlertDialog("Некоректная URL ссылка.")
  43.             return false
  44.         }
  45.  
  46.         return true
  47.  
  48.     }
  49.  
  50.     override fun responseServer(responseRequest: String) {
  51.         view.createAlertDialog(responseRequest)
  52.  
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement