-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathViperGod.cpp
118 lines (106 loc) · 3.81 KB
/
ViperGod.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// ViperGod.cpp
// Jako
//
// Created by John Zakharov on 06.08.16.
// Copyright © 2016 Outlaw Studio. All rights reserved.
//
#include "ViperGod.hpp"
Mitsoko::God Mitsoko::God::shared;
using std::cout;
using std::endl;
using Mitsoko::PresenterBase;
Mitsoko::God::ViewId Mitsoko::God::createView(const std::string &viewName,const void *handle){
std::vector<std::shared_ptr<Disposable>> disposablesVector;
auto presenterPointer = this->_createView<R::ModulesTuple>(viewName,handle,disposablesVector);
if(presenterPointer){
const auto viewId = this->nextViewId++;
// cout << "presenterPointer[" << viewId << "] = " << presenterPointer << ", handle = " << handle << endl;
// this->viewPool.insert({viewId,viewPointer});
this->presenters.insert({viewId, presenterPointer});
this->disposables.insert({viewId,std::move(disposablesVector)});
return viewId;
}else{
return -1;
}
}
template<>
std::shared_ptr<PresenterBase> Mitsoko::God::_createView<std::tuple<>>(const std::string &viewName,
const void *handle,
std::vector<std::shared_ptr<Disposable>> &disposables)
{
return nullptr;
}
void Mitsoko::God::viewWillAppear(ViewId viewId){
auto it=this->presenters.find(viewId);
if(it != this->presenters.end()){
auto presenterPointer = it->second;
auto viewBasePointer = presenterPointer->getViewBase();
if(viewBasePointer->willAppear){
viewBasePointer->willAppear();
}
/*if(it->second->willAppear){
it->second->willAppear();
}*/
}
}
void Mitsoko::God::viewDidAppear(ViewId viewId){
auto it=this->presenters.find(viewId);
if(it != this->presenters.end()){
// auto viewBasePointer = it->second;
auto presenterPointer = it->second;
auto viewBasePointer = presenterPointer->getViewBase();
if(viewBasePointer->didAppear){
viewBasePointer->didAppear();
}
}
}
void Mitsoko::God::viewWillDisappear(ViewId viewId){
auto it=this->presenters.find(viewId);
if(it != this->presenters.end()){
// auto viewBasePointer = it->second;
auto presenterPointer = it->second;
auto viewBasePointer = presenterPointer->getViewBase();
if(viewBasePointer->willDisappear){
viewBasePointer->willDisappear();
}
}
}
const void* Mitsoko::God::destroyView(ViewId viewId){
const void *res = nullptr;
const auto it = this->presenters.find(viewId);
if(it != this->presenters.end()){
// res = it->second->handle;
res = it->second->getViewBase()->handle;
this->presenters.erase(it);
}
const auto it2 = this->disposables.find(viewId);
if(it2 != this->disposables.end()){
for(const auto &disposablePointer:it2->second){
disposablePointer->dispose();
}
it2->second.clear();
this->disposables.erase(it2);
}
return res;
}
void Mitsoko::God::sendMessageToView(ViewId viewId,int messageCode,std::string argumentsString){
const auto it = this->presenters.find(viewId);
if(it != this->presenters.end()){
if(it->second->getViewBase()->messageReceived){
it->second->getViewBase()->messageReceived(messageCode, std::move(argumentsString));
}
}else{
cout<<"view not found with id "<<viewId<<endl;
}
}
#ifdef __ANDROID__
void Mitsoko::God::onActivityResult(ViewId viewId,int requestCode,int resultCode,jobject data){
const auto it=this->presenters.find(viewId);
if(it != this->presenters.end()){
it->second->getViewBase()->onActivityResult(requestCode,resultCode,data);
}else{
cout<<"view not found with id "<<viewId<<endl;
}
}
#endif