forked from pockethub/PocketHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntents.java
More file actions
351 lines (305 loc) · 9.03 KB
/
Intents.java
File metadata and controls
351 lines (305 loc) · 9.03 KB
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*
* Copyright 2012 GitHub Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile;
import static org.eclipse.egit.github.core.RepositoryId.createFromUrl;
import android.content.Intent;
import java.io.Serializable;
import java.util.ArrayList;
import org.eclipse.egit.github.core.Gist;
import org.eclipse.egit.github.core.GistFile;
import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryId;
import org.eclipse.egit.github.core.User;
/**
* Helper for creating intents
*/
public class Intents {
/**
* Prefix for all intents created
*/
public static final String INTENT_PREFIX = "com.github.mobile.";
/**
* Prefix for all extra data added to intents
*/
public static final String INTENT_EXTRA_PREFIX = INTENT_PREFIX + "extra.";
/**
* Repository handle
*/
public static final String EXTRA_REPOSITORY = INTENT_EXTRA_PREFIX
+ "REPOSITORY";
/**
* Repository ids collection handle
*/
public static final String EXTRA_REPOSITORIES = INTENT_EXTRA_PREFIX
+ "REPOSITORIES";
/**
* Repository name
*/
public static final String EXTRA_REPOSITORY_NAME = INTENT_EXTRA_PREFIX
+ "REPOSITORY_NAME";
/**
* Repository owner
*/
public static final String EXTRA_REPOSITORY_OWNER = INTENT_EXTRA_PREFIX
+ "REPOSITORY_OWNER";
/**
* Issue number
*/
public static final String EXTRA_ISSUE_NUMBER = INTENT_EXTRA_PREFIX
+ "ISSUE_NUMBER";
/**
* Issue handle
*/
public static final String EXTRA_ISSUE = INTENT_EXTRA_PREFIX + "ISSUE";
/**
* Issue number collection handle
*/
public static final String EXTRA_ISSUE_NUMBERS = INTENT_EXTRA_PREFIX
+ "ISSUE_NUMBERS";
/**
* Gist id
*/
public static final String EXTRA_GIST_ID = INTENT_EXTRA_PREFIX + "GIST_ID";
/**
* List of Gist ids
*/
public static final String EXTRA_GIST_IDS = INTENT_EXTRA_PREFIX
+ "GIST_IDS";
/**
* Gist handle
*/
public static final String EXTRA_GIST = INTENT_EXTRA_PREFIX + "GIST";
/**
* Gist file handle
*/
public static final String EXTRA_GIST_FILE = INTENT_EXTRA_PREFIX
+ "GIST_FILE";
/**
* User handle
*/
public static final String EXTRA_USER = INTENT_EXTRA_PREFIX + "USER";
/**
* {@link ArrayList} handle of {@link User} objects
*/
public static final String EXTRA_USERS = INTENT_EXTRA_PREFIX + "USERS";
/**
* Issue filter handle
*/
public static final String EXTRA_ISSUE_FILTER = INTENT_EXTRA_PREFIX
+ "ISSUE_FILTER";
/**
* Comment body
*/
public static final String EXTRA_COMMENT_BODY = INTENT_EXTRA_PREFIX
+ "COMMENT_BODY";
/**
* Comments handle
*/
public static final String EXTRA_COMMENTS = INTENT_EXTRA_PREFIX
+ "COMMENTS";
/**
* Comment handle
*/
public static final String EXTRA_COMMENT = INTENT_EXTRA_PREFIX + "COMMENT";
/**
* Integer position
*/
public static final String EXTRA_POSITION = INTENT_EXTRA_PREFIX
+ "POSITION";
/**
* Base commit name
*/
public static final String EXTRA_BASE = INTENT_EXTRA_PREFIX + "BASE";
/**
* Base commit names
*/
public static final String EXTRA_BASES = INTENT_EXTRA_PREFIX + "BASES";
/**
* Base commit name
*/
public static final String EXTRA_HEAD = INTENT_EXTRA_PREFIX + "HEAD";
/**
* Handle to a {@link String} path
*/
public static final String EXTRA_PATH = INTENT_EXTRA_PREFIX + "PATH";
/**
* Resolve the {@link RepositoryId} referenced by the given intent
*
* @param intent
* @return repository id
*/
public static RepositoryId repoFrom(Intent intent) {
String repoName = intent.getStringExtra(EXTRA_REPOSITORY_NAME);
String repoOwner = intent.getStringExtra(EXTRA_REPOSITORY_OWNER);
return RepositoryId.create(repoOwner, repoName);
}
/**
* Builder for generating an intent configured with extra data such as an
* issue, repository, or gist
*/
public static class Builder {
private final Intent intent;
/**
* Create builder with suffix
*
* @param actionSuffix
*/
public Builder(String actionSuffix) {
// actionSuffix = e.g. "repos.VIEW"
intent = new Intent(INTENT_PREFIX + actionSuffix);
}
/**
* Add repository id to intent being built up
*
* @param repositoryId
* @return this builder
*/
public Builder repo(RepositoryId repositoryId) {
return add(EXTRA_REPOSITORY_NAME, repositoryId.getName()).add(
EXTRA_REPOSITORY_OWNER, repositoryId.getOwner());
}
/**
* Add repository to intent being built up
*
* @param repository
* @return this builder
*/
public Builder repo(Repository repository) {
return add(EXTRA_REPOSITORY, repository);
}
/**
* Add issue to intent being built up
*
* @param issue
* @return this builder
*/
public Builder issue(Issue issue) {
return repo(createFromUrl(issue.getHtmlUrl())).add(EXTRA_ISSUE,
issue).add(EXTRA_ISSUE_NUMBER, issue.getNumber());
}
/**
* Add gist to intent being built up
*
* @param gist
* @return this builder
*/
public Builder gist(Gist gist) {
return add(EXTRA_GIST, gist);
}
/**
* Add gist id to intent being built up
*
* @param gist
* @return this builder
*/
public Builder gist(String gist) {
return add(EXTRA_GIST_ID, gist);
}
/**
* Add gist file to intent being built up
*
* @param file
* @return this builder
*/
public Builder gistFile(GistFile file) {
return add(EXTRA_GIST_FILE, file);
}
/**
* Add user to intent being built up
*
* @param user
* @return this builder;
*/
public Builder user(User user) {
return add(EXTRA_USER, user);
}
/**
* Add extra field data value to intent being built up
*
* @param fieldName
* @param value
* @return this builder
*/
public Builder add(String fieldName, String value) {
intent.putExtra(fieldName, value);
return this;
}
/**
* Add extra field data values to intent being built up
*
* @param fieldName
* @param values
* @return this builder
*/
public Builder add(String fieldName, CharSequence[] values) {
intent.putExtra(fieldName, values);
return this;
}
/**
* Add extra field data value to intent being built up
*
* @param fieldName
* @param value
* @return this builder
*/
public Builder add(String fieldName, int value) {
intent.putExtra(fieldName, value);
return this;
}
/**
* Add extra field data value to intent being built up
*
* @param fieldName
* @param values
* @return this builder
*/
public Builder add(String fieldName, int[] values) {
intent.putExtra(fieldName, values);
return this;
}
/**
* Add extra field data value to intent being built up
*
* @param fieldName
* @param values
* @return this builder
*/
public Builder add(String fieldName, boolean[] values) {
intent.putExtra(fieldName, values);
return this;
}
/**
* Add extra field data value to intent being built up
*
* @param fieldName
* @param value
* @return this builder
*/
public Builder add(String fieldName, Serializable value) {
intent.putExtra(fieldName, value);
return this;
}
/**
* Get built intent
*
* @return intent
*/
public Intent toIntent() {
return intent;
}
}
}