|
1 | | -package otus.homework.coroutines |
2 | | - |
3 | | -import kotlinx.coroutines.CoroutineName |
4 | | -import kotlinx.coroutines.CoroutineScope |
5 | | -import kotlinx.coroutines.Dispatchers |
6 | | -import kotlinx.coroutines.Job |
7 | | -import kotlinx.coroutines.async |
8 | | -import kotlinx.coroutines.launch |
9 | | - |
10 | | - |
11 | | - |
12 | | -class CatsPresenter( |
13 | | - private val catsService: CatsService, |
14 | | - private val catsImagesService: CatsImageService, |
15 | | - private val presenterScope: CoroutineScope = CoroutineScope(Dispatchers.Main + CoroutineName("CatsCoroutine")) |
16 | | -) { |
17 | | - |
18 | | - private var _catsView: ICatsView? = null |
19 | | - private var job: Job? = null |
20 | | - |
21 | | - fun onInitComplete() { |
22 | | - try { |
23 | | - job = presenterScope.launch { |
24 | | - val fact = async { catsService.getCatFact() }.await() |
25 | | - val catImages:List<CatImage> = async { catsImagesService.getCatImage() }.await() |
26 | | - _catsView?.populate(fact, catImages.first()) |
27 | | - } |
28 | | - } catch (ex: Exception) { |
29 | | - if (ex is java.net.SocketTimeoutException) { |
30 | | - _catsView?.onError("Unable to get response from server") |
31 | | - } |
32 | | - CrashMonitor.trackWarning() |
33 | | - } |
34 | | - } |
35 | | - |
36 | | - fun onStop() { |
37 | | - job?.cancel() |
38 | | - } |
39 | | - |
40 | | - |
41 | | - fun attachView(catsView: ICatsView) { |
42 | | - _catsView = catsView |
43 | | - } |
44 | | - |
45 | | - fun detachView() { |
46 | | - _catsView = null |
47 | | - } |
48 | | -} |
| 1 | +//package otus.homework.coroutines |
| 2 | +// |
| 3 | +//import kotlinx.coroutines.CoroutineName |
| 4 | +//import kotlinx.coroutines.CoroutineScope |
| 5 | +//import kotlinx.coroutines.Dispatchers |
| 6 | +//import kotlinx.coroutines.Job |
| 7 | +//import kotlinx.coroutines.async |
| 8 | +//import kotlinx.coroutines.launch |
| 9 | +// |
| 10 | +// |
| 11 | +// |
| 12 | +//class CatsPresenter( |
| 13 | +// private val catsService: CatsService, |
| 14 | +// private val catsImagesService: CatsImageService, |
| 15 | +// private val presenterScope: CoroutineScope = CoroutineScope(Dispatchers.Main + CoroutineName("CatsCoroutine")) |
| 16 | +//) { |
| 17 | +// |
| 18 | +// private var _catsView: ICatsView? = null |
| 19 | +// private var job: Job? = null |
| 20 | +// |
| 21 | +// fun onInitComplete() { |
| 22 | +// try { |
| 23 | +// job = presenterScope.launch { |
| 24 | +// val fact = async { catsService.getCatFact() }.await() |
| 25 | +// val catImages:List<CatImage> = async { catsImagesService.getCatImage() }.await() |
| 26 | +// _catsView?.populate(fact, catImages.first()) |
| 27 | +// } |
| 28 | +// } catch (ex: Exception) { |
| 29 | +// if (ex is java.net.SocketTimeoutException) { |
| 30 | +// _catsView?.onError("Unable to get response from server") |
| 31 | +// } |
| 32 | +// CrashMonitor.trackWarning("Error") |
| 33 | +// } |
| 34 | +// } |
| 35 | +// |
| 36 | +// fun onStop() { |
| 37 | +// job?.cancel() |
| 38 | +// } |
| 39 | +// |
| 40 | +// |
| 41 | +// fun attachView(catsView: ICatsView) { |
| 42 | +// _catsView = catsView |
| 43 | +// } |
| 44 | +// |
| 45 | +// fun detachView() { |
| 46 | +// _catsView = null |
| 47 | +// } |
| 48 | +//} |
0 commit comments