-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathandroid_templates.py
226 lines (160 loc) · 6.27 KB
/
android_templates.py
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
module = '''
package com.{{ lower_project_name }}.{{ lower_module_name }};
import android.content.Context;
import android.view.LayoutInflater;
import com.{{ lower_project_name }}.network.{{ upper_project_name }}NetworkService;
import javax.inject.Named;
import dagger.Module;
import dagger.Provides;
@Module
public class {{ upper_module_name }}Module {
private final {{ upper_module_name }}Activity activity;
public {{ upper_module_name }}Module({{ upper_module_name }}Activity activity) { this.activity = activity; }
@Provides
@Named("activity")
Context provideActivityContext() {
return activity;
}
@Provides
{{ upper_module_name }}Presenter providePresenter({{ upper_module_name }}Interactor interactor) {
return new {{ upper_module_name }}Presenter(activity, interactor);
}
@Provides
{{ upper_module_name }}Interactor provideInteractor({{ upper_project_name }}NetworkService networkService) {
return new {{ upper_module_name }}Interactor(networkService);
}
@Provides
LayoutInflater provideLayoutInflater() {
return activity.getLayoutInflater();
}
}
'''
activity = '''
package com.{{ lower_project_name }}.{{ lower_module_name }};
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.{{ lower_project_name }}.ApplicationBase;
import javax.inject.Inject;
public class {{ upper_module_name }}Activity extends AppCompatActivity {
private {{ upper_module_name }}Component m{{ upper_module_name }}Component;
@Inject
{{ upper_module_name }}Presenter mPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.{{ lower_project_name }}.R.layout.activity_{{ lower_module_name }});
m{{ upper_module_name }}Component = Dagger{{ upper_module_name }}Component.builder()
.applicationComponent(((ApplicationBase) getApplication()).getAppComponent())
.{{ lower_module_name }}Module(new {{ upper_module_name }}Module(this))
.build();
m{{ upper_module_name }}Component.inject(this);
mPresenter.onCreate(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
// Make Presenter calls here
}
}
'''
component = '''
package com.{{ lower_project_name }}.{{ lower_module_name }};
import com.{{ lower_project_name }}.dependencies.ActivityScope;
import com.{{ lower_project_name }}.dependencies.ApplicationComponent;
import dagger.Component;
@ActivityScope
@Component(dependencies = ApplicationComponent.class, modules = { {{ upper_module_name }}Module.class })
public interface {{ upper_module_name }}Component {
void inject({{ upper_module_name }}Activity activity);
}
'''
interactor = '''
package com.{{ lower_project_name }}.{{ lower_module_name }};
import com.{{ lower_project_name }}.network.{{ upper_project_name }}NetworkService;
public class {{ upper_module_name }}Interactor {
private {{ upper_project_name }}NetworkService mNetworkService;
public {{ upper_module_name }}Interactor({{ upper_project_name }}NetworkService networkService) {
mNetworkService = networkService;
}
}
'''
presenter = '''
package com.{{ lower_project_name }}.{{ lower_module_name }};
import android.os.Bundle;
import com.{{ lower_project_name }}.BasePresenter;
import org.json.JSONObject;
public class {{ upper_module_name }}Presenter implements BasePresenter {
private {{ upper_module_name }}Activity mActivity;
private {{ upper_module_name }}Interactor mInteractor;
public {{ upper_module_name }}Presenter({{ upper_module_name }}Activity activity, {{ upper_module_name }}Interactor interactor) {
mActivity = activity;
mInteractor = interactor;
}
@Override
public void onCreate(Bundle savedInstanceState) {
}
@Override
public void onResume() {
}
@Override
public void updateWithMachineInfo(JSONObject obj) {
}
}
'''
fragment = '''
package com.{{ lower_project_name }}.{{ lower_module_name }};
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.flexline.R;
public class {{ upper_fragment_name }}Fragment extends Fragment {
private View view;
private {{ upper_module_name }}Activity mActivity;
private {{ upper_module_name }}Presenter mPresenter;
public {{ upper_fragment_name }}Fragment() {}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_{{ lower_fragment_name }}, container, false);
mActivity = ({{ upper_module_name }}Activity) getActivity();
mPresenter = mActivity.mPresenter;
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// Button listeners, etc
super.onActivityCreated(savedInstanceState);
}
}
'''
activity_xml = '''<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_{{ lower_module_name }}"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.{{ lower_project_name }}.{{ lower_module_name }}.{{ upper_module_name }}Activity">
</RelativeLayout>
'''
fragment_xml = '''<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent">
</RelativeLayout>
'''
update_android_manifest_xml = '''
<!-- ////// COPY THE BELOW CODE AND PASTE INTO AndroidManifest.xml ////// -->
<activity
android:name=".{{ lower_module_name }}.{{ upper_module_name }}Activity">
</activity>
<!-- ////// ////// -->
'''