├── .gitignore
├── Gank.iml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── app.iml
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── veaer
│ │ └── gank
│ │ ├── App.java
│ │ ├── data
│ │ ├── VAll.java
│ │ ├── VData.java
│ │ └── VDay.java
│ │ ├── model
│ │ ├── VDate.java
│ │ └── VFeed.java
│ │ ├── request
│ │ ├── CacheInterceptor.java
│ │ ├── Line.java
│ │ ├── LineFactory.java
│ │ └── LineRetrofit.java
│ │ ├── util
│ │ ├── DateUtil.java
│ │ ├── DownloadUtil.java
│ │ ├── FileUtils.java
│ │ ├── ShareUtil.java
│ │ └── StringUtil.java
│ │ ├── view
│ │ ├── AboutActivity.java
│ │ ├── GankDetailActivity.java
│ │ ├── GankListActivity.java
│ │ ├── GankWebActivity.java
│ │ ├── HomeActivity.java
│ │ └── PictureActivity.java
│ │ └── widget
│ │ ├── BaseActivity.java
│ │ ├── BaseViewHolder.java
│ │ ├── ToolbarActivity.java
│ │ ├── VSpan.java
│ │ └── ZoomImageView.java
│ └── res
│ ├── anim
│ ├── slide_right_in.xml
│ └── slide_right_out.xml
│ ├── drawable
│ └── about.xml
│ ├── layout
│ ├── about_activity.xml
│ ├── detail_activity_gank.xml
│ ├── detail_view_holder_detail.xml
│ ├── home_activity_gank.xml
│ ├── list_activity_gank_list.xml
│ ├── list_view_holder_list_item.xml
│ ├── picture_activity.xml
│ ├── view_toolbar.xml
│ └── web_activity_gank.xml
│ ├── menu
│ ├── menu_gank.xml
│ ├── menu_picture.xml
│ ├── menu_share.xml
│ └── menu_web.xml
│ ├── mipmap-hdpi
│ └── gank_launcher.png
│ ├── mipmap-mdpi
│ └── gank_launcher.png
│ ├── mipmap-xhdpi
│ ├── gank_launcher.png
│ ├── ic_arrow_back_white_18dp.png
│ ├── ic_launcher.png
│ ├── ic_refresh_white_24dp.png
│ ├── ic_save_white_24dp.png
│ └── ic_share_white_24dp.png
│ ├── mipmap-xxhdpi
│ └── gank_launcher.png
│ ├── values-v19
│ └── dimens.xml
│ └── values
│ ├── android_material_design_colours.xml
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── config.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 | .idea
9 | /*.keystore
--------------------------------------------------------------------------------
/Gank.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Gank-Veaer
2 |
3 | Android for daimajia's meizi
4 |
5 |
6 |
7 |
8 |
9 | 欣赏妹纸,查看干货Feed的小应用,数据来自[代码家](https://github.com/daimajia)的干货网站:[Gank.io](http://gank.io)
10 |
11 |
12 |
13 | 直接下载:http://fir.im/gankapp
14 |
15 | v1.0.0()
16 |
17 | * 在[大B哥](https://github.com/Bob1993)的影响下的又一次修复bug
18 |
19 | v0.0.2(2.07MB)
20 |
21 | * 作者很懒
22 | * 这是一个完全重构的版本
23 | * 基本所有代码重构
24 | * 应该还有坑
25 | * 就是这样,喵~
26 |
27 | v0.0.1(5.82MB)
28 |
29 | * 作者很懒
30 | * 这是从无到有的一个版本
31 | * 就是这样,喵~
32 |
33 |
34 |
35 | 2015.11.08:打算接着搞
36 |
37 | # 源代码在 GPLv3 协议下发布
38 |
39 | [LICENSE](/LICENSE)
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateVeaerDebugAndroidTestSources
19 | generateVeaerDebugSources
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 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'me.tatarka.retrolambda'
3 |
4 | def keyStore = file('../gank.keystore')
5 | Properties properties = new Properties()
6 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
7 |
8 | android {
9 | compileSdkVersion rootProject.ext.android.compileSdkVersion
10 | buildToolsVersion rootProject.ext.android.buildToolsVersion
11 |
12 | defaultConfig {
13 | applicationId rootProject.ext.android.applicationId
14 | minSdkVersion rootProject.ext.android.minSdkVersion
15 | targetSdkVersion rootProject.ext.android.targetSdkVersion
16 | versionCode rootProject.ext.android.versionCode
17 | versionName rootProject.ext.android.versionName
18 | }
19 |
20 | packagingOptions {
21 | exclude 'META-INF/services/javax.annotation.processing.Processor'
22 | exclude 'META-INF/rxjava.properties'
23 | }
24 |
25 | dexOptions {
26 | incremental false
27 | javaMaxHeapSize "4g"
28 | }
29 |
30 | lintOptions {
31 | disable "InvalidPackage", 'MissingTranslation', 'ExtraTranslation'
32 | abortOnError false
33 | lintConfig file("lint.xml")
34 | }
35 |
36 | signingConfigs {
37 | debug {
38 |
39 | }
40 |
41 | release {
42 | storeFile keyStore
43 | storePassword properties.getProperty('STOREPASS')
44 | keyAlias properties.getProperty('KEYALIAS')
45 | keyPassword properties.getProperty('KEYPASS')
46 | }
47 | }
48 |
49 | buildTypes {
50 | debug {
51 | manifestPlaceholders = [UMENG_APPKEY: properties.getProperty('UMENGAPPKEY')]
52 |
53 | }
54 |
55 | release {
56 | buildConfigField "boolean", "LOG_DEBUG", "false"
57 |
58 | manifestPlaceholders = [UMENG_APPKEY: properties.getProperty('UMENGAPPKEY')]
59 |
60 | minifyEnabled false
61 | zipAlignEnabled true
62 | debuggable false
63 | shrinkResources true
64 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
65 | signingConfig signingConfigs.release
66 |
67 | applicationVariants.all { variant ->
68 | variant.outputs.each { output ->
69 | def outputFile = output.outputFile
70 | if (outputFile != null && outputFile.name.endsWith('.apk')) {
71 | def fileName = "Gank_v${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
72 | output.outputFile = new File(outputFile.parent, fileName)
73 | }
74 | }
75 | }
76 | }
77 | }
78 |
79 | productFlavors {
80 | "Veaer"{}
81 | "smartisan"{}
82 | "wandoujia"{}
83 | }
84 |
85 | productFlavors.all {
86 | flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
87 | }
88 |
89 | compileOptions {
90 | sourceCompatibility JavaVersion.VERSION_1_8
91 | targetCompatibility JavaVersion.VERSION_1_8
92 | }
93 | }
94 |
95 | dependencies {
96 | compile fileTree(dir: 'libs', include: ['*.jar'])
97 | compile rootProject.ext.dependencies["design"]
98 | compile rootProject.ext.dependencies["appcompat-v7"]
99 | compile rootProject.ext.dependencies["recyclerview-v7"]
100 | compile rootProject.ext.dependencies["glide"]
101 | compile rootProject.ext.dependencies["okhttp"]
102 | compile rootProject.ext.dependencies["retrofit"]
103 | compile rootProject.ext.dependencies["rxandroid"]
104 | compile rootProject.ext.dependencies["butterknife"]
105 | compile rootProject.ext.dependencies["umeng-analytics"]
106 | }
107 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Veaer/AndroidStudio/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 | -dontwarn rx.**
19 | -dontwarn retrofit.**
20 | -keep class retrofit.** { *; }
21 | -keepclasseswithmembers class * {
22 | @retrofit.http.* ;
23 | }
24 |
25 | # umeng
26 | -keepclassmembers class * {
27 | public (org.json.JSONObject);
28 | }
29 |
30 | -keepclassmembers enum * {
31 | public static **[] values();
32 | public static ** valueOf(java.lang.String);
33 | }
34 |
35 | # ButterKnife 7
36 |
37 | -keep class butterknife.** { *; }
38 | -dontwarn butterknife.internal.**
39 | -keep class **$$ViewBinder { *; }
40 |
41 | -keepclasseswithmembernames class * {
42 | @butterknife.* ;
43 | }
44 |
45 | -keepclasseswithmembernames class * {
46 | @butterknife.* ;
47 | }
48 |
49 | -keep public class android.support.v7.widget.** { *; }
50 | -keep public class android.support.v7.internal.widget.** { *; }
51 | -keep public class android.support.v7.internal.view.menu.** { *; }
52 |
53 | -keep public class * extends android.support.v4.view.ActionProvider {
54 | public (android.content.Context);
55 | }
56 |
57 |
58 | -dontwarn android.support.design.**
59 | -keep class android.support.design.** { *; }
60 | -keep interface android.support.design.** { *; }
61 | -keep public class android.support.design.R$* { *; }
62 |
63 | # OkHttp
64 | -keepattributes Signature
65 | -keepattributes *Annotation*
66 | -keep class com.squareup.okhttp.** { *; }
67 | -keep interface com.squareup.okhttp.** { *; }
68 | -dontwarn com.squareup.okhttp.**
69 |
70 | ## Retrolambda specific rules ##
71 |
72 | # as per official recommendation: https://github.com/evant/gradle-retrolambda#proguard
73 | -dontwarn java.lang.invoke.*
74 |
75 |
76 | # Okio
77 | -keep class sun.misc.Unsafe { *; }
78 | -dontwarn java.nio.file.*
79 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
80 | -dontwarn okio.**
81 |
82 | # RxJava 0.21
83 |
84 | -keep class rx.schedulers.Schedulers {
85 | public static ;
86 | }
87 | -keep class rx.schedulers.ImmediateScheduler {
88 | public ;
89 | }
90 | -keep class rx.schedulers.TestScheduler {
91 | public ;
92 | }
93 | -keep class rx.schedulers.Schedulers {
94 | public static ** test();
95 | }
96 |
97 |
98 | # Glide specific rules #
99 | # https://github.com/bumptech/glide
100 |
101 | -keep public class * implements com.bumptech.glide.module.GlideModule
102 | -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
103 | **[] $VALUES;
104 | public *;
105 | }
106 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
26 |
29 |
32 |
33 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
49 |
50 |
55 |
56 |
61 |
62 |
67 |
68 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/App.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | /**
7 | * Created by Veaer on 15/8/15.
8 | */
9 | public class App extends Application {
10 |
11 | public static Context sContext;
12 |
13 | @Override public void onCreate() {
14 | super.onCreate();
15 | sContext = this;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/data/VAll.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.data;
2 |
3 | import com.veaer.gank.model.VFeed;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by Veaer on 15/9/17.
9 | */
10 | public class VAll extends VData {
11 | public List results;
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/data/VData.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.data;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by Veaer on 15/9/17.
7 | */
8 | public class VData implements Serializable {
9 | public boolean error;
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/data/VDay.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.data;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 | import com.veaer.gank.model.VFeed;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Created by Veaer on 15/9/17.
10 | */
11 | public class VDay extends VData {
12 |
13 | public List category;
14 | public Results results;
15 |
16 | public class Results {
17 | @SerializedName("iOS") public List iosList;
18 | @SerializedName("福利") public List picList;
19 | @SerializedName("Android") public List androidList;
20 | @SerializedName("拓展资源") public List newsList;
21 | @SerializedName("瞎推荐") public List introsList;
22 | @SerializedName("休息视频") public List videoList;
23 | @SerializedName("前端") public List frontList;
24 | @SerializedName("App") public List appList;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/model/VDate.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.model;
2 |
3 | import java.io.Serializable;
4 | import java.util.Calendar;
5 | import java.util.Date;
6 |
7 | /**
8 | * Created by Veaer on 15/8/19.
9 | */
10 | public class VDate implements Serializable {
11 | public String TIME;
12 | public int YEAR;
13 | public int MONTH;
14 | public int DAY;
15 |
16 | public VDate(Date published) {
17 | Calendar calendar = Calendar.getInstance();
18 | calendar.setTime(published);
19 | this.YEAR = calendar.get(Calendar.YEAR);
20 | this.MONTH = calendar.get(Calendar.MONTH) + 1;
21 | this.DAY = calendar.get(Calendar.DAY_OF_MONTH);
22 | this.TIME = this.YEAR + "/" + this.MONTH + "/" + this.DAY;
23 | }
24 |
25 | public String getMonth() {
26 | String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
27 | return months[this.MONTH - 1];
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/model/VFeed.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.model;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | /**
7 | * Created by Veaer on 15/9/17.
8 | */
9 | public class VFeed implements Serializable {
10 | public String who;
11 | public Date publishedAt;
12 | public String desc;
13 | public String url;
14 | public String type;
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/request/CacheInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.request;
2 |
3 |
4 | import com.squareup.okhttp.Interceptor;
5 | import com.squareup.okhttp.Request;
6 | import com.squareup.okhttp.Response;
7 |
8 | import java.io.IOException;
9 |
10 |
11 | public class CacheInterceptor implements Interceptor {
12 | public static final String TAG = CacheInterceptor.class.getSimpleName();
13 | private static final String CACHE_CONTROL = "Cache-Control";
14 |
15 | @Override
16 | public Response intercept(Chain chain) throws IOException {
17 |
18 | Request request = chain.request();
19 | Response response = chain.proceed(request);
20 | return response.newBuilder()
21 | .header(CACHE_CONTROL, "public, max-age=" + 60 * 60 * 24) // 缓存一天
22 | .build();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/request/Line.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Drakeet
3 | *
4 | * This file is part of Meizhi
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.veaer.gank.request;
21 |
22 |
23 | import com.veaer.gank.data.VAll;
24 | import com.veaer.gank.data.VDay;
25 |
26 | import retrofit.http.GET;
27 | import retrofit.http.Path;
28 | import rx.Observable;
29 |
30 | /**
31 | * Created by Veaer on 15/9/8.
32 | */
33 | public interface Line {
34 |
35 | @GET("/data/all/1/1") Observable getSplashData();
36 |
37 | @GET("/day/{year}/{month}/{day}") Observable getDayData(@Path("year") int year, @Path("month") int month, @Path("day") int day);
38 |
39 | @GET("/data/福利/10/{page}") Observable getPicList(@Path("page") int page);
40 |
41 | @GET("/data/休息视频/10/{page}") Observable getVideoData(@Path("page") int page);
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/request/LineFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Drakeet
3 | *
4 | * This file is part of Meizhi
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.veaer.gank.request;
21 |
22 | /**
23 | * Created by Veaer on 15/9/8.
24 | */
25 | public class LineFactory {
26 | static Line sSingleton = null;
27 |
28 | public static Line getSingleton() {
29 | synchronized (LineFactory.class) {
30 | if (sSingleton == null) {
31 | sSingleton = new LineRetrofit().getService();
32 | }
33 | return sSingleton;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/request/LineRetrofit.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Drakeet
3 | *
4 | * This file is part of Meizhi
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.veaer.gank.request;
21 |
22 | import com.google.gson.Gson;
23 | import com.google.gson.GsonBuilder;
24 | import com.squareup.okhttp.Cache;
25 | import com.squareup.okhttp.OkHttpClient;
26 | import com.veaer.gank.util.FileUtils;
27 |
28 | import java.io.File;
29 | import java.io.IOException;
30 | import java.util.concurrent.TimeUnit;
31 |
32 | import retrofit.RestAdapter;
33 | import retrofit.client.OkClient;
34 | import retrofit.converter.GsonConverter;
35 |
36 | /**
37 | * Created by Veaer on 15/9/8.
38 | */
39 | public class LineRetrofit {
40 |
41 | final Line service;
42 | private static Cache cache;
43 |
44 | final static Gson gson =
45 | new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").serializeNulls().create();
46 |
47 | LineRetrofit() {
48 | OkHttpClient client = new OkHttpClient();
49 | client.setReadTimeout(12, TimeUnit.SECONDS);
50 | int cacheSize = 10 * 1024 * 1024; // 10 MiB
51 | cache = new Cache(FileUtils.getHttpCacheDir(), cacheSize);
52 | client.setCache(cache);
53 | client.networkInterceptors().add(new CacheInterceptor());
54 |
55 | RestAdapter restAdapter = new RestAdapter.Builder().setClient(new OkClient(client))
56 | .setEndpoint("http://gank.avosapps.com/api/")
57 | .setConverter(new GsonConverter(gson))
58 | .build();
59 | service = restAdapter.create(Line.class);
60 | }
61 |
62 | public Line getService() {
63 | return service;
64 | }
65 |
66 | public static void clearCache() {
67 | try {
68 | cache.flush();
69 | } catch (IOException e) {
70 | e.printStackTrace();
71 | }
72 | for (File item : FileUtils.getHttpCacheDir().listFiles()) {
73 | item.delete();
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/util/DateUtil.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.util;
2 |
3 | import java.text.DateFormat;
4 | import java.text.SimpleDateFormat;
5 | import java.util.Calendar;
6 | import java.util.Date;
7 |
8 | /**
9 | * Created by Veaer on 15/8/18.
10 | */
11 | public class DateUtil {
12 |
13 | public static String getToday() {
14 | return toDate(new Date());
15 | }
16 |
17 | public static String toDate(Date date) {
18 | DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
19 | return dateFormat.format(date);
20 | }
21 |
22 | public static String toDate(Date date, int add) {
23 | Calendar calendar = Calendar.getInstance();
24 | calendar.setTime(date);
25 | calendar.add(Calendar.DATE, add);
26 | return toDate(calendar.getTime());
27 | }
28 |
29 | public static Date getLastdayDate(Date date) {
30 | Calendar calendar = Calendar.getInstance();
31 | calendar.setTime(date);
32 | calendar.add(Calendar.DATE, -1);
33 | return calendar.getTime();
34 | }
35 |
36 | public static Date getNextdayDate(Date date) {
37 | Calendar calendar = Calendar.getInstance();
38 | calendar.setTime(date);
39 | calendar.add(Calendar.DATE, 1);
40 | return calendar.getTime();
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/util/DownloadUtil.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.util;
2 |
3 | import android.os.Environment;
4 |
5 | import com.bumptech.glide.RequestManager;
6 | import com.bumptech.glide.request.target.Target;
7 |
8 | import java.io.Closeable;
9 | import java.io.File;
10 | import java.io.FileInputStream;
11 | import java.io.FileOutputStream;
12 | import java.io.IOException;
13 | import java.nio.channels.FileChannel;
14 |
15 | import rx.Observable;
16 |
17 | /**
18 | * Created by Veaer on 16/1/12.
19 | */
20 | public class DownloadUtil {
21 |
22 | public static Observable download(RequestManager rm, String url) {
23 | return download(rm, url, Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
24 | }
25 |
26 | public static Observable download(RequestManager rm, String url, int width, int height) {
27 | return Observable.defer(() -> {
28 | try {
29 | return Observable.just(rm.load(url).downloadOnly(width, height).get());
30 | } catch (Exception e) {
31 | return Observable.error(e);
32 | }
33 | });
34 | }
35 |
36 | public static Observable copy(File from, File to) {
37 | return Observable.defer(() -> {
38 | FileInputStream input = null;
39 | FileOutputStream output = null;
40 |
41 | try {
42 | input = new FileInputStream(from);
43 | output = new FileOutputStream(to);
44 |
45 | FileChannel inputChannel = input.getChannel();
46 | FileChannel outputChannel = output.getChannel();
47 |
48 | inputChannel.transferTo(0, inputChannel.size(), outputChannel);
49 |
50 | return Observable.just(to);
51 | } catch (IOException e) {
52 | return Observable.error(e);
53 | } finally {
54 | closeQuietly(input);
55 | closeQuietly(output);
56 | }
57 | });
58 | }
59 |
60 | public static Observable mkdirsIfNotExists() {
61 | File appDir = new File(Environment.getExternalStorageDirectory(), "Gank");
62 | return Observable.defer(() -> {
63 | if (appDir.mkdirs() || appDir.isDirectory()) {
64 | return Observable.just(appDir);
65 | } else {
66 | return Observable.error(new IOException("Failed to mkdirs " + appDir.getPath()));
67 | }
68 | });
69 | }
70 |
71 | private static void closeQuietly(Closeable closeable) {
72 | if (closeable != null) {
73 | try {
74 | closeable.close();
75 | } catch (IOException ignored) {
76 | }
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/util/FileUtils.java:
--------------------------------------------------------------------------------
1 |
2 | package com.veaer.gank.util;
3 |
4 | import android.os.Environment;
5 |
6 | import com.veaer.gank.App;
7 |
8 | import java.io.File;
9 |
10 |
11 | public class FileUtils {
12 | private static final String HTTP_CACHE_DIR = "http";
13 |
14 | public static File getHttpCacheDir() {
15 | if (Environment.getExternalStorageState().equals(
16 | Environment.MEDIA_MOUNTED)) {
17 | return new File(App.sContext.getExternalCacheDir(), HTTP_CACHE_DIR);
18 | }
19 | return new File(App.sContext.getCacheDir(), HTTP_CACHE_DIR);
20 | }
21 |
22 | // public static Observable saveImageAndGetPathObservable(Context context, String url,
23 | // String title) {
24 | // return Observable.create(new Observable.OnSubscribe() {
25 | // @Override public void call(Subscriber super Bitmap> subscriber) {
26 | // Bitmap bitmap = null;
27 | // try {
28 | //// bitmap = Picasso.with(context).load(url).get();
29 | // } catch (IOException e) {
30 | // subscriber.onError(e);
31 | // }
32 | // if (bitmap == null) {
33 | // subscriber.onError(new Exception("无法下载到图片"));
34 | // }
35 | // subscriber.onNext(bitmap);
36 | // subscriber.onCompleted();
37 | // }
38 | // }).flatMap(bitmap -> {
39 | // File appDir = new File(Environment.getExternalStorageDirectory(), "Gank");
40 | // if (!appDir.exists()) {
41 | // appDir.mkdir();
42 | // }
43 | // String fileName = title.replace('/', '-') + ".jpg";
44 | // File file = new File(appDir, fileName);
45 | // try {
46 | // FileOutputStream fos = new FileOutputStream(file);
47 | // assert bitmap != null;
48 | // bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
49 | // fos.flush();
50 | // fos.close();
51 | // } catch (IOException e) {
52 | // e.printStackTrace();
53 | // }
54 | //
55 | // Uri uri = Uri.fromFile(file);
56 | // // 通知图库更新
57 | // Intent scannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
58 | // context.sendBroadcast(scannerIntent);
59 | // return Observable.just(uri);
60 | // }).subscribeOn(Schedulers.io());
61 | // }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/util/ShareUtil.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.util;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 |
7 | import com.veaer.gank.R;
8 |
9 | /**
10 | * Created by Veaer on 15/10/24.
11 | */
12 | public class ShareUtil {
13 | public static void share(Context context) {
14 | share(context, context.getString(R.string.share_words));
15 | }
16 |
17 |
18 | public static void shareImage(Context context, Uri uri, String title) {
19 | Intent shareIntent = new Intent();
20 | shareIntent.setAction(Intent.ACTION_SEND);
21 | shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
22 | shareIntent.setType("image/jpeg");
23 | context.startActivity(Intent.createChooser(shareIntent, title));
24 | }
25 |
26 |
27 | public static void share(Context context, String extraText) {
28 | Intent intent = new Intent(Intent.ACTION_SEND);
29 | intent.setType("text/plain");
30 | intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.share));
31 | intent.putExtra(Intent.EXTRA_TEXT, extraText);
32 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
33 | context.startActivity(
34 | Intent.createChooser(intent, context.getString(R.string.share)));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/util/StringUtil.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.util;
2 |
3 | import android.graphics.Typeface;
4 | import android.text.SpannableStringBuilder;
5 | import android.text.Spanned;
6 | import android.text.style.ForegroundColorSpan;
7 | import android.text.style.StyleSpan;
8 |
9 | import com.veaer.gank.model.VFeed;
10 | import com.veaer.gank.widget.VSpan;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Created by Veaer on 15/8/30.
16 | */
17 | public class StringUtil {
18 | public static String generateGankLink(String time) {
19 | return "http://gank.io/" + time;
20 | }
21 |
22 | public static SpannableStringBuilder generateFeed(List feedList, int color) {
23 | SpannableStringBuilder builder = new SpannableStringBuilder();
24 | int start;
25 | for (VFeed feed : feedList) {
26 | start = builder.length();
27 | builder.append(" • ");
28 | builder.setSpan(new StyleSpan(Typeface.BOLD), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
29 | start = builder.length();
30 | builder.append(feed.desc);
31 | builder.setSpan(new VSpan(feed.url, feed.desc), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
32 | builder.setSpan(new ForegroundColorSpan(color), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
33 | builder.append("(");
34 | builder.append(feed.who);
35 | builder.append(")\n");
36 | }
37 | return builder;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/view/AboutActivity.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.view;
2 |
3 | import android.content.ClipData;
4 | import android.content.ClipboardManager;
5 | import android.content.Context;
6 | import android.os.Bundle;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 | import android.widget.TextView;
10 |
11 | import com.veaer.gank.BuildConfig;
12 | import com.veaer.gank.R;
13 | import com.veaer.gank.util.ShareUtil;
14 | import com.veaer.gank.widget.ToolbarActivity;
15 |
16 | import butterknife.Bind;
17 |
18 | /**
19 | * Created by Veaer on 15/10/24.
20 | */
21 | public class AboutActivity extends ToolbarActivity {
22 |
23 | @Bind(R.id.tv_version) TextView mVersionTextView;
24 | @Bind(R.id.donate_tv) TextView donateTv;
25 |
26 | @Override
27 | public int getContentViewID() {
28 | return R.layout.about_activity;
29 | }
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 |
35 | mVersionTextView.append(BuildConfig.VERSION_NAME);
36 | donateTv.setOnClickListener(v -> {
37 | ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
38 | cmb.setPrimaryClip(ClipData.newPlainText(null, getText(R.string.email)));
39 | showToast(getString(R.string.copy_finish));
40 | });
41 |
42 | }
43 |
44 | @Override public boolean onCreateOptionsMenu(Menu menu) {
45 | getMenuInflater().inflate(R.menu.menu_share, menu);
46 | return true;
47 | }
48 |
49 |
50 | @Override public boolean onOptionsItemSelected(MenuItem item) {
51 | if(R.id.menu_share == item.getItemId()) {
52 | ShareUtil.share(this);
53 | return true;
54 | }
55 | return super.onOptionsItemSelected(item);
56 | }
57 |
58 | @Override
59 | public boolean canBack() {
60 | return true;
61 | }
62 |
63 | @Override
64 | public String getToolBarTitle() {
65 | return getString(R.string.action_about);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/view/GankDetailActivity.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.view;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.design.widget.CollapsingToolbarLayout;
6 | import android.support.v4.content.ContextCompat;
7 | import android.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.support.v7.widget.Toolbar;
10 | import android.text.method.LinkMovementMethod;
11 | import android.view.LayoutInflater;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.widget.ImageView;
17 | import android.widget.TextView;
18 |
19 | import com.bumptech.glide.Glide;
20 | import com.veaer.gank.R;
21 | import com.veaer.gank.data.VDay;
22 | import com.veaer.gank.model.VDate;
23 | import com.veaer.gank.model.VFeed;
24 | import com.veaer.gank.util.ShareUtil;
25 | import com.veaer.gank.util.StringUtil;
26 | import com.veaer.gank.widget.BaseActivity;
27 | import com.veaer.gank.widget.BaseViewHolder;
28 |
29 | import java.util.List;
30 |
31 | import butterknife.Bind;
32 | import butterknife.OnClick;
33 | import rx.Subscription;
34 | import rx.android.schedulers.AndroidSchedulers;
35 |
36 | /**
37 | * Created by Veaer on 15/8/19.
38 | */
39 | public class GankDetailActivity extends BaseActivity {
40 |
41 | @Bind(R.id.toolbar) Toolbar mToolbar;
42 | @Bind(R.id.collapsing_toolbar) CollapsingToolbarLayout mCollapsingToolbarLayout;
43 | @Bind(R.id.head_image) ImageView headImage;
44 | @Bind(R.id.rv_detail_list) RecyclerView detailListView;
45 | private VDay today;
46 | private VDate vDate;
47 | private String headUrl;
48 |
49 | @Override
50 | public int getContentViewID() {
51 | return R.layout.detail_activity_gank;
52 | }
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 |
58 | vDate = (VDate)getIntent().getSerializableExtra("current_time");
59 | headUrl = getIntent().getStringExtra("title_bg");
60 |
61 | initToolBar();
62 | initData();
63 | }
64 |
65 | @OnClick(R.id.head_image) public void toPicActivity(View view) {
66 | Intent picIntent = new Intent(this, PictureActivity.class);
67 | picIntent.putExtra("image_url", headUrl);
68 | picIntent.putExtra("image_title", vDate.TIME);
69 | startActivity(picIntent);
70 | }
71 |
72 | @Override public boolean onCreateOptionsMenu(Menu menu) {
73 | getMenuInflater().inflate(R.menu.menu_share, menu);
74 | return true;
75 | }
76 |
77 |
78 | @Override public boolean onOptionsItemSelected(MenuItem item) {
79 | if(R.id.menu_share == item.getItemId()) {
80 | ShareUtil.share(this, getString(R.string.share_url) + StringUtil.generateGankLink(vDate.TIME) + getString(R.string.app_download));
81 | return true;
82 | }
83 | return super.onOptionsItemSelected(item);
84 | }
85 |
86 | public void initToolBar() {
87 | mCollapsingToolbarLayout.setTitle(vDate.TIME);
88 |
89 | setSupportActionBar(mToolbar);
90 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
91 | mToolbar.setNavigationOnClickListener(v -> GankDetailActivity.this.onBackPressed());
92 |
93 | Glide.with(mActivity)
94 | .load(headUrl)
95 | .centerCrop()
96 | .into(headImage);
97 | }
98 |
99 | public void initData() {
100 | Subscription s = mLine.getDayData(vDate.YEAR, vDate.MONTH, vDate.DAY)
101 | .observeOn(AndroidSchedulers.mainThread())
102 | .subscribe(dayData -> {
103 | int fuliIndex = dayData.category.indexOf("福利");
104 | dayData.category.remove(fuliIndex);
105 | this.today = dayData;
106 | initView();
107 | }, throwable -> loadError(throwable));
108 | addSubscription(s);
109 | }
110 |
111 | public void initView() {
112 | detailListView.setLayoutManager(new LinearLayoutManager(mContext));
113 | detailListView.setAdapter(new GankDetailAdapter());
114 | }
115 |
116 |
117 | public class GankDetailAdapter extends RecyclerView.Adapter {
118 | private LayoutInflater mLayoutInflater;
119 |
120 | public GankDetailAdapter() {
121 | mLayoutInflater = LayoutInflater.from(mContext);
122 | }
123 |
124 | @Override
125 | public int getItemCount() {
126 | return today.category.size();
127 | }
128 |
129 | @Override
130 | public void onBindViewHolder(DetailViewHolder holder, int position) {
131 | switch (today.category.get(position)) {
132 | case "iOS":
133 | holder.bindViews(today.category.get(position), today.results.iosList);
134 | break;
135 | case "App":
136 | holder.bindViews(today.category.get(position), today.results.appList);
137 | break;
138 | case "Android":
139 | holder.bindViews(today.category.get(position), today.results.androidList);
140 | break;
141 | case "拓展资源":
142 | holder.bindViews(today.category.get(position), today.results.newsList);
143 | break;
144 | case "休息视频":
145 | holder.bindViews(today.category.get(position), today.results.videoList);
146 | break;
147 | case "瞎推荐":
148 | holder.bindViews(today.category.get(position), today.results.introsList);
149 | break;
150 | case "前端":
151 | holder.bindViews(today.category.get(position), today.results. frontList);
152 | break;
153 | }
154 | }
155 |
156 |
157 | @Override
158 | public DetailViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
159 | return new DetailViewHolder(mLayoutInflater.inflate(R.layout.detail_view_holder_detail, parent, false));
160 | }
161 | }
162 |
163 | public class DetailViewHolder extends BaseViewHolder {
164 | @Bind(R.id.category_title) TextView titleTv;
165 | @Bind(R.id.feed_content) TextView contentTv;
166 |
167 | public DetailViewHolder(View view) {
168 | super(view);
169 | }
170 |
171 | public void bindViews(String title, List feeds) {
172 | titleTv.setText(title);
173 | contentTv.setText(StringUtil.generateFeed(feeds, ContextCompat.getColor(mContext, R.color.theme_primary)));
174 | contentTv.setMovementMethod(LinkMovementMethod.getInstance());
175 | }
176 | }
177 |
178 | }
179 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/view/GankListActivity.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.view;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v4.widget.SwipeRefreshLayout;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | import com.bumptech.glide.Glide;
17 | import com.veaer.gank.App;
18 | import com.veaer.gank.R;
19 | import com.veaer.gank.data.VAll;
20 | import com.veaer.gank.model.VDate;
21 | import com.veaer.gank.model.VFeed;
22 | import com.veaer.gank.widget.BaseViewHolder;
23 | import com.veaer.gank.widget.ToolbarActivity;
24 |
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 | import butterknife.Bind;
29 | import rx.Observable;
30 | import rx.Subscription;
31 | import rx.android.schedulers.AndroidSchedulers;
32 |
33 | /**
34 | * Created by Veaer on 15/8/16.
35 | */
36 | public class GankListActivity extends ToolbarActivity {
37 | @Bind(R.id.rv_gank_list)
38 | RecyclerView gankListRv;
39 | @Bind(R.id.swipe_refresh_layout)
40 | SwipeRefreshLayout refreshLayout;
41 | int nextPage = 1;
42 | boolean canAdd = true;
43 | GankListAdapter gankListAdapter = new GankListAdapter();
44 | List feedsList = new ArrayList<>();
45 |
46 | @Override
47 | public int getContentViewID() {
48 | return R.layout.list_activity_gank_list;
49 | }
50 |
51 | @Override
52 | protected void onCreate(Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | initGankViews();
55 | initGankData(1, true);
56 | }
57 |
58 | public void initGankViews() {
59 | gankListRv.setAdapter(gankListAdapter);
60 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
61 | gankListRv.setLayoutManager(linearLayoutManager);
62 | gankListRv.addOnScrollListener(getScrollToBottomListener(linearLayoutManager));
63 |
64 | refreshLayout.setColorSchemeResources(R.color.refresh_progress_3,
65 | R.color.refresh_progress_2, R.color.refresh_progress_1);
66 | refreshLayout.setOnRefreshListener(() -> initGankData(1, true));
67 | }
68 |
69 | public void initGankData(int page, boolean is_refresh) {
70 | if(!canAdd) {
71 | showToast("滑不动了哟");
72 | setRefreshing(false);
73 | return;
74 | }
75 |
76 | Subscription s = Observable.zip(mLine.getPicList(page), mLine.getVideoData(page),
77 | this::mixPicVideo)
78 | .map(all -> all.results)
79 | .flatMap(Observable::from)
80 | .toSortedList((feed1, feed2) -> feed2.publishedAt.compareTo(feed1.publishedAt))
81 | .observeOn(AndroidSchedulers.mainThread())
82 | .subscribe(all -> {
83 | if (all.size() < 10) {
84 | canAdd = false;
85 | }
86 | if (all.size() == 0) {
87 | canAdd = false;
88 | showToast("滑不动了哟");
89 | }
90 | if (is_refresh) {
91 | feedsList.clear();
92 | feedsList.addAll(all);
93 | nextPage = 1;
94 | } else {
95 | feedsList.addAll(all);
96 | }
97 | gankListAdapter.notifyDataSetChanged();
98 | setRefreshing(false);
99 | }, this::loadError);
100 | addSubscription(s);
101 | }
102 |
103 | public VAll mixPicVideo(VAll pic, VAll video) {
104 | int maxLength = pic.results.size() < video.results.size() ? pic.results.size() : video.results.size();
105 | for (int i = 0; i < maxLength; i++) {
106 | VFeed f = pic.results.get(i);
107 | f.desc = video.results.get(i).desc;
108 | }
109 | return pic;
110 | }
111 |
112 | public void onToolbarClick() {
113 | gankListRv.smoothScrollToPosition(0);
114 | }
115 |
116 | public void setRefreshing(boolean refreshing) {
117 | if (!refreshing) {
118 | refreshLayout.postDelayed(() -> {
119 | if(!this.isFinishing()) {
120 | refreshLayout.setRefreshing(false);
121 | }
122 | }, 1000);
123 | } else {
124 | refreshLayout.setRefreshing(true);
125 | }
126 | }
127 |
128 | RecyclerView.OnScrollListener getScrollToBottomListener(final LinearLayoutManager linearLayoutManager) {
129 | return new RecyclerView.OnScrollListener() {
130 | @Override public void onScrolled(RecyclerView rv, int dx, int dy) {
131 | boolean isBottom = linearLayoutManager.findLastVisibleItemPosition() == (feedsList.size() - 1);
132 | if (!refreshLayout.isRefreshing() && isBottom) {
133 | refreshLayout.setRefreshing(true);
134 | nextPage++;
135 | initGankData(nextPage, false);
136 | }
137 | }
138 | };
139 | }
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 | public class GankListAdapter extends RecyclerView.Adapter {
148 | private LayoutInflater mLayoutInflater;
149 |
150 | public GankListAdapter() {
151 | mLayoutInflater = LayoutInflater.from(App.sContext);
152 | }
153 |
154 | @Override
155 | public int getItemCount() {
156 | return feedsList.size();
157 | }
158 |
159 | @Override
160 | public void onBindViewHolder(GankItemViewHolder holder, int position) {
161 | if(position < feedsList.size()) holder.bindViews(feedsList.get(position));
162 | }
163 |
164 | @Override
165 | public GankItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
166 | return new GankItemViewHolder(mLayoutInflater.inflate(R.layout.list_view_holder_list_item, parent, false));
167 | }
168 | }
169 |
170 | public class GankItemViewHolder extends BaseViewHolder {
171 | VDate vDate;
172 |
173 | @Bind(R.id.desc)
174 | TextView descTv;
175 | @Bind(R.id.year)
176 | TextView yearTv;
177 | @Bind(R.id.month)
178 | TextView monthTv;
179 | @Bind(R.id.day)
180 | TextView dayTv;
181 | @Bind(R.id.picture)
182 | ImageView pictureIV;
183 | VFeed vFeed;
184 |
185 | public GankItemViewHolder(View view) {
186 | super(view);
187 | view.setOnClickListener(v -> toActivity());
188 | }
189 |
190 | public void toActivity() {
191 | Intent intent = new Intent(getApplicationContext(), GankDetailActivity.class);
192 | intent.putExtra("current_time", vDate);
193 | intent.putExtra("title_bg", vFeed.url);
194 | startActivity(intent);
195 | overridePendingTransition(R.anim.slide_right_in, R.anim.slide_right_out);
196 | }
197 |
198 | public void bindViews(VFeed vFeed) {
199 | this.vFeed = vFeed;
200 | vDate = new VDate(vFeed.publishedAt);
201 | yearTv.append(vDate.YEAR + "");
202 | monthTv.setText(vDate.getMonth());
203 | dayTv.append(vDate.DAY + "");
204 | descTv.setText(vFeed.desc);
205 | Glide.with(mActivity)
206 | .load(vFeed.url)
207 | .centerCrop()
208 | .into(pictureIV);
209 | }
210 | }
211 |
212 |
213 | @Override
214 | public boolean onCreateOptionsMenu(Menu menu) {
215 | getMenuInflater().inflate(R.menu.menu_gank, menu);
216 | return true;
217 | }
218 |
219 | @Override
220 | public boolean onOptionsItemSelected(MenuItem item) {
221 | int id = item.getItemId();
222 | if(id == R.id.action_about) {
223 | Intent aboutIntent = new Intent(this, AboutActivity.class);
224 | startActivity(aboutIntent);
225 | overridePendingTransition(R.anim.slide_right_in, R.anim.slide_right_out);
226 | return true;
227 | }
228 | return super.onOptionsItemSelected(item);
229 | }
230 |
231 | @Override
232 | public String getToolBarTitle() {
233 | return "HISTORY";
234 | }
235 | }
236 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/view/GankWebActivity.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.view;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.view.KeyEvent;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 | import android.view.View;
10 | import android.webkit.WebChromeClient;
11 | import android.webkit.WebSettings;
12 | import android.webkit.WebView;
13 | import android.webkit.WebViewClient;
14 |
15 | import com.veaer.gank.R;
16 | import com.veaer.gank.util.ShareUtil;
17 | import com.veaer.gank.widget.ToolbarActivity;
18 |
19 | import butterknife.Bind;
20 |
21 |
22 | /**
23 | * Created by Veaer on 15/8/27.
24 | */
25 | public class GankWebActivity extends ToolbarActivity {
26 |
27 | @Bind(R.id.webView) WebView mWebView;
28 |
29 | String mUrl, mTitle;
30 |
31 | @Override
32 | public boolean canBack() {
33 | return true;
34 | }
35 |
36 | @Override
37 | public int getContentViewID() {
38 | return R.layout.web_activity_gank;
39 | }
40 |
41 | @Override
42 | protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | mUrl = getIntent().getStringExtra("feed_url");
45 | mTitle = getIntent().getStringExtra("feed_title");
46 |
47 | mToolbar.setTitle(mTitle);
48 |
49 | WebSettings settings = mWebView.getSettings();
50 | settings.setJavaScriptEnabled(true);
51 | settings.setLoadWithOverviewMode(true);
52 | settings.setAppCacheEnabled(true);
53 | settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
54 | settings.setSupportZoom(true);
55 | settings.setDomStorageEnabled(true);
56 | mWebView.setWebChromeClient(new ChromeClient());
57 | mWebView.setWebViewClient(new LoveClient());
58 | mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
59 |
60 | mWebView.loadUrl(mUrl);
61 |
62 | }
63 |
64 | public void onToolbarClick() {
65 | mWebView.scrollTo(0,0);
66 | }
67 |
68 |
69 | private void refresh() {
70 | mWebView.reload();
71 | }
72 |
73 | @Override public boolean onCreateOptionsMenu(Menu menu) {
74 | getMenuInflater().inflate(R.menu.menu_web, menu);
75 | return true;
76 | }
77 |
78 |
79 | @Override public boolean onOptionsItemSelected(MenuItem item) {
80 | int id = item.getItemId();
81 | switch (id) {
82 | case R.id.menu_refresh:
83 | refresh();
84 | return true;
85 | case R.id.menu_share:
86 | ShareUtil.share(this, getString(R.string.share_url) + mUrl + getString(R.string.app_download));
87 | return true;
88 | case R.id.menu_open:
89 | Intent intent = new Intent();
90 | intent.setAction(Intent.ACTION_VIEW);
91 | Uri uri = Uri.parse(mUrl);
92 | intent.setData(uri);
93 | if (intent.resolveActivity(getPackageManager()) != null) {
94 | startActivity(intent);
95 | } else {
96 | showToast(getString(R.string.open_fail));
97 | }
98 | return true;
99 | }
100 | return super.onOptionsItemSelected(item);
101 | }
102 |
103 | @Override
104 | public void onPause() {
105 | super.onPause();
106 | mWebView.reload();
107 | }
108 |
109 | @Override
110 | public boolean onKeyDown(int keyCode, KeyEvent event) {
111 | if (event.getAction() == KeyEvent.ACTION_DOWN) {
112 | switch (keyCode) {
113 | case KeyEvent.KEYCODE_BACK:
114 | if (mWebView.canGoBack()) {
115 | mWebView.goBack();
116 | }
117 | else {
118 | finish();
119 | }
120 | return true;
121 | }
122 | }
123 | return super.onKeyDown(keyCode, event);
124 | }
125 |
126 | private class ChromeClient extends WebChromeClient {
127 |
128 | @Override public void onProgressChanged(WebView view, int newProgress) {
129 | super.onProgressChanged(view, newProgress);
130 | }
131 |
132 | @Override public void onReceivedTitle(WebView view, String title) {
133 | super.onReceivedTitle(view, title);
134 | setTitle(title);
135 | }
136 | }
137 |
138 | private class LoveClient extends WebViewClient {
139 |
140 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
141 | if (url != null) view.loadUrl(url);
142 | return true;
143 | }
144 | }
145 |
146 | }
147 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/view/HomeActivity.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.view;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.ImageView;
7 | import android.widget.RelativeLayout;
8 | import android.widget.TextView;
9 |
10 | import com.bumptech.glide.Glide;
11 | import com.veaer.gank.R;
12 | import com.veaer.gank.data.VAll;
13 | import com.veaer.gank.data.VDay;
14 | import com.veaer.gank.model.VDate;
15 | import com.veaer.gank.widget.BaseActivity;
16 |
17 | import butterknife.Bind;
18 | import butterknife.OnClick;
19 | import rx.Subscription;
20 | import rx.android.schedulers.AndroidSchedulers;
21 |
22 | /**
23 | * Created by Veaer on 15/8/31.
24 | */
25 | public class HomeActivity extends BaseActivity {
26 | @Bind(R.id.home_pic)
27 | ImageView picIv;
28 | @Bind(R.id.home_pic_via)
29 | TextView picViaTv;
30 | @Bind(R.id.home_video)
31 | TextView videoTv;
32 | @Bind(R.id.home_video_via)
33 | TextView videoViaTv;
34 | @Bind(R.id.home_to_list)
35 | TextView listTv;
36 | @Bind(R.id.home_video_layout)
37 | RelativeLayout videoRl;
38 |
39 | VDay vDay;
40 | VDate vDate;
41 |
42 | @Override
43 | public int getContentViewID() {
44 | return R.layout.home_activity_gank;
45 | }
46 |
47 | @Override
48 | protected void onCreate(Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 | loadData();
51 | }
52 |
53 | public void initView() {
54 | Glide.with(mActivity).load(vDay.results.picList.get(0).url).into(picIv);
55 | picViaTv.append("via." + vDay.results.picList.get(0).who);
56 | videoTv.setText(vDay.results.videoList.get(0).desc);
57 | videoViaTv.append(vDate.TIME + " via." + vDay.results.videoList.get(0).who);
58 | videoRl.setOnClickListener(v -> listener("video"));
59 | listTv.setOnClickListener(v -> listener("list"));
60 | }
61 |
62 | public void listener(String label) {
63 | Intent intent;
64 | if(label.equals("video")) {
65 | intent = new Intent(HomeActivity.this, GankWebActivity.class);
66 | intent.putExtra("feed_url", vDay.results.videoList.get(0).url);
67 | intent.putExtra("feed_title", vDay.results.videoList.get(0).desc);
68 | } else {
69 | intent = new Intent(HomeActivity.this, GankListActivity.class);
70 | }
71 | startActivity(intent);
72 | overridePendingTransition(R.anim.slide_right_in, R.anim.slide_right_out);
73 | }
74 |
75 | public void loadData() {
76 | Subscription splash = mLine.getSplashData()
77 | .observeOn(AndroidSchedulers.mainThread())
78 | .subscribe(this::getTodayData, this::loadError);
79 | addSubscription(splash);
80 | }
81 |
82 | public void getTodayData(VAll vAll) {
83 | vDate = new VDate(vAll.results.get(0).publishedAt);
84 | Subscription today = mLine.getDayData(vDate.YEAR, vDate.MONTH, vDate.DAY)
85 | .observeOn(AndroidSchedulers.mainThread())
86 | .subscribe(vDay -> {
87 | this.vDay = vDay;
88 | initView();
89 | }, this::loadError);
90 | addSubscription(today);
91 | }
92 |
93 | @OnClick(R.id.home_pic) public void toPicActivity(View view) {
94 | Intent picIntent = new Intent(this, PictureActivity.class);
95 | picIntent.putExtra("image_url", vDay.results.picList.get(0).url);
96 | picIntent.putExtra("image_title", vDate.TIME);
97 | startActivity(picIntent);
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/view/PictureActivity.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.view;
2 |
3 | import android.media.MediaScannerConnection;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.v4.util.Pair;
7 | import android.util.Log;
8 | import android.view.Menu;
9 | import android.view.MenuItem;
10 |
11 | import com.bumptech.glide.Glide;
12 | import com.veaer.gank.R;
13 | import com.veaer.gank.util.DownloadUtil;
14 | import com.veaer.gank.util.ShareUtil;
15 | import com.veaer.gank.widget.ToolbarActivity;
16 | import com.veaer.gank.widget.ZoomImageView;
17 |
18 | import java.io.File;
19 |
20 | import butterknife.Bind;
21 | import rx.Observable;
22 | import rx.android.schedulers.AndroidSchedulers;
23 | import rx.functions.Func2;
24 | import rx.schedulers.Schedulers;
25 |
26 | /**
27 | * Created by Veaer on 15/10/27.
28 | */
29 | public class PictureActivity extends ToolbarActivity{
30 |
31 | public static final String EXTRA_IMAGE_URL = "image_url";
32 | public static final String EXTRA_IMAGE_TITLE = "image_title";
33 |
34 | @Bind(R.id.picture)
35 | ZoomImageView mImageView;
36 |
37 | String mImageUrl, mImageTitle;
38 |
39 |
40 |
41 |
42 | private void parseIntent() {
43 | mImageUrl = getIntent().getStringExtra(EXTRA_IMAGE_URL);
44 | mImageTitle = getIntent().getStringExtra(EXTRA_IMAGE_TITLE);
45 | mToolbar.setTitle(mImageTitle);
46 | }
47 |
48 |
49 | @Override protected void onCreate(Bundle savedInstanceState) {
50 | super.onCreate(savedInstanceState);
51 | parseIntent();
52 |
53 | Glide.with(this).load(mImageUrl).into(mImageView);
54 |
55 | setAppBarAlpha(0.7f);
56 |
57 | mImageView.setOnViewTapListener(((zoomImageView, x, y) -> hideOrShowToolbar()));
58 |
59 | }
60 |
61 | private String makeFileName() {
62 | return String.format("%d.jpg", System.currentTimeMillis());
63 | }
64 |
65 | private void notifyMediaScanning(File file) {
66 | MediaScannerConnection.scanFile(
67 | mContext.getApplicationContext(),
68 | new String[]{file.getPath()}, null, null);
69 | }
70 |
71 | @Override public boolean onCreateOptionsMenu(Menu menu) {
72 | getMenuInflater().inflate(R.menu.menu_picture, menu);
73 | return true;
74 | }
75 |
76 | @Override public boolean onOptionsItemSelected(MenuItem item) {
77 |
78 | Observable observableDownload = DownloadUtil.download(Glide.with(this), mImageUrl);
79 |
80 | Observable observableSave = DownloadUtil.mkdirsIfNotExists()
81 | .map(directory -> new File(directory, makeFileName()))
82 | .withLatestFrom(observableDownload, (Func2>) Pair::new)
83 | .flatMap(pair -> DownloadUtil.copy(pair.second, pair.first));
84 | switch (item.getItemId()) {
85 | case R.id.action_share:
86 | observableSave
87 | .subscribeOn(Schedulers.io())
88 | .observeOn(AndroidSchedulers.mainThread())
89 | .subscribe(file -> ShareUtil.shareImage(this, Uri.fromFile(file), "分享妹纸到..."), e -> Log.e(TAG, "Failed to share picture", e));
90 | return true;
91 | case R.id.action_save:
92 | observableSave
93 | .subscribeOn(Schedulers.io())
94 | .observeOn(AndroidSchedulers.mainThread())
95 | .subscribe(file -> {
96 | notifyMediaScanning(file);
97 | showToast(file.getName());
98 | }, e -> Log.e(TAG, "Failed to save picture", e));
99 | showToast(getString(R.string.save_finish));
100 | return true;
101 | }
102 |
103 | return super.onOptionsItemSelected(item);
104 | }
105 |
106 |
107 | @Override
108 | public int getContentViewID() {
109 | return R.layout.picture_activity;
110 | }
111 |
112 | @Override
113 | public boolean canBack() {
114 | return true;
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/widget/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.widget;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.os.Bundle;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.v7.app.AppCompatActivity;
8 |
9 | import com.umeng.analytics.MobclickAgent;
10 | import com.veaer.gank.R;
11 | import com.veaer.gank.request.Line;
12 | import com.veaer.gank.request.LineFactory;
13 |
14 | import butterknife.ButterKnife;
15 | import rx.Subscription;
16 | import rx.subscriptions.CompositeSubscription;
17 |
18 | /**
19 | * Created by Veaer on 15/8/15.
20 | */
21 | public class BaseActivity extends AppCompatActivity {
22 | public static String TAG;
23 | public Activity mActivity;
24 | public Context mContext;
25 | protected final static Line mLine = LineFactory.getSingleton();
26 | protected CompositeSubscription mCompositeSubscription;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | if(getContentViewID() != 0) {
32 | setContentView(getContentViewID());
33 | ButterKnife.bind(this);
34 | }
35 | this.mContext = this.mActivity = this;
36 | TAG = this.getClass().getSimpleName();
37 | }
38 |
39 | @Override
40 | public void onResume() {
41 | super.onResume();
42 | MobclickAgent.onResume(this);
43 | }
44 |
45 | @Override
46 | public void onPause() {
47 | super.onPause();
48 | MobclickAgent.onPause(this);
49 | }
50 |
51 | @Override
52 | protected void onDestroy() {
53 | super.onDestroy();
54 | if(getContentViewID() != 0) {
55 | ButterKnife.unbind(this);
56 | }
57 | if (this.mCompositeSubscription != null) {
58 | this.mCompositeSubscription.unsubscribe();
59 | }
60 | }
61 |
62 | public CompositeSubscription getCompositeSubscription() {
63 | if (this.mCompositeSubscription == null) {
64 | this.mCompositeSubscription = new CompositeSubscription();
65 | }
66 |
67 | return this.mCompositeSubscription;
68 | }
69 |
70 | public void addSubscription(Subscription s) {
71 | if (this.mCompositeSubscription == null) {
72 | this.mCompositeSubscription = new CompositeSubscription();
73 | }
74 |
75 | this.mCompositeSubscription.add(s);
76 | }
77 |
78 | public int getContentViewID() {
79 | return 0;
80 | }
81 |
82 | public void loadError(Throwable throwable) {
83 | showToast(getString(R.string.error));
84 | }
85 |
86 |
87 | public void showToast(int id) {
88 | showToast(getString(id));
89 | }
90 |
91 | public void showToast(String msg) {
92 | if(null == msg) { return; }
93 | Snackbar.make(getWindow().getDecorView(), msg, Snackbar.LENGTH_SHORT).show();
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/widget/BaseViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.widget;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 |
6 | import butterknife.ButterKnife;
7 |
8 | /**
9 | * Created by Veaer on 15/8/19.
10 | */
11 | public class BaseViewHolder extends RecyclerView.ViewHolder {
12 |
13 | public BaseViewHolder(View view) {
14 | super(view);
15 | ButterKnife.bind(this, view);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/widget/ToolbarActivity.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.widget;
2 |
3 | import android.os.Build;
4 | import android.os.Bundle;
5 | import android.support.design.widget.AppBarLayout;
6 | import android.support.v7.app.ActionBar;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.MenuItem;
9 | import android.view.animation.DecelerateInterpolator;
10 |
11 | import com.veaer.gank.R;
12 |
13 | import butterknife.Bind;
14 |
15 |
16 | public abstract class ToolbarActivity extends BaseActivity {
17 |
18 | @Bind(R.id.app_bar_layout)
19 | protected AppBarLayout mAppBar;
20 | @Bind(R.id.toolbar)
21 | protected Toolbar mToolbar;
22 | protected boolean mIsHidden = false;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | initToolBar();
28 |
29 | }
30 |
31 | public void initToolBar() {
32 | if(Build.VERSION.SDK_INT >= 21) {
33 | mAppBar.setElevation(10.6f);
34 | }
35 | mToolbar.setTitle(getToolBarTitle());
36 | mToolbar.setTitleTextColor(getResources().getColor(R.color.theme_text_color));
37 | mToolbar.setOnClickListener(view -> onToolbarClick());
38 | setSupportActionBar(mToolbar);
39 | if(canBack()) {
40 | ActionBar actionBar = getSupportActionBar();
41 | if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);
42 | }
43 | }
44 |
45 | public String getToolBarTitle() {
46 | return "";
47 | }
48 |
49 | public boolean canBack() {
50 | return false;
51 | }
52 |
53 | public void onToolbarClick() {}
54 |
55 | protected void setAppBarAlpha(float alpha) {
56 | mAppBar.setAlpha(alpha);
57 | }
58 |
59 | protected void hideOrShowToolbar() {
60 | mAppBar.animate()
61 | .translationY(mIsHidden ? 0 : -mAppBar.getHeight())
62 | .setInterpolator(new DecelerateInterpolator(2))
63 | .start();
64 |
65 | mIsHidden = !mIsHidden;
66 | }
67 |
68 | @Override
69 | public boolean onOptionsItemSelected(MenuItem item) {
70 | if (item.getItemId() == android.R.id.home) {
71 | onBackPressed();
72 | return true;
73 | }
74 | else {
75 | return super.onOptionsItemSelected(item);
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/widget/VSpan.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.widget;
2 |
3 | import android.content.Intent;
4 | import android.support.annotation.NonNull;
5 | import android.text.TextPaint;
6 | import android.text.style.ClickableSpan;
7 | import android.view.View;
8 |
9 | import com.veaer.gank.view.GankWebActivity;
10 |
11 | /**
12 | * Created by Veaer on 15/10/26.
13 | */
14 | public class VSpan extends ClickableSpan {
15 | private String title;
16 | private String url;
17 |
18 | public VSpan(String url, String title) {
19 | super();
20 | this.url = url;
21 | this.title = title;
22 | }
23 |
24 | @Override
25 | public void updateDrawState(@NonNull TextPaint ds) {
26 | super.updateDrawState(ds);
27 | ds.setUnderlineText(false);
28 | }
29 |
30 | @Override
31 | public void onClick(View widget) {
32 | Intent intent = new Intent(widget.getContext(), GankWebActivity.class);
33 | intent.putExtra("feed_url", url);
34 | intent.putExtra("feed_title", title);
35 | widget.getContext().startActivity(intent);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/veaer/gank/widget/ZoomImageView.java:
--------------------------------------------------------------------------------
1 | package com.veaer.gank.widget;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Matrix;
7 | import android.graphics.RectF;
8 | import android.graphics.drawable.Drawable;
9 | import android.net.Uri;
10 | import android.os.Build;
11 | import android.util.AttributeSet;
12 | import android.view.GestureDetector;
13 | import android.view.MotionEvent;
14 | import android.view.ScaleGestureDetector;
15 | import android.view.VelocityTracker;
16 | import android.view.View;
17 | import android.view.ViewConfiguration;
18 | import android.view.ViewTreeObserver;
19 | import android.widget.ImageView;
20 | import android.widget.OverScroller;
21 | import android.widget.Scroller;
22 |
23 | /**
24 | * Created by Veaer on 16/1/24.
25 | */
26 | public class ZoomImageView extends ImageView implements View.OnTouchListener,
27 | ViewTreeObserver.OnGlobalLayoutListener {
28 |
29 | /**
30 | * Interface definition for a callback to be invoked when the Photo is
31 | * tapped with a single tap.
32 | *
33 | * @author tomasz.zawada@gmail.com
34 | */
35 | public static interface OnPhotoTapListener {
36 | /**
37 | * A callback to receive where the user taps on a photo. You will only
38 | * receive a callback if the user taps on the actual photo, tapping on
39 | * 'whitespace' will be ignored.
40 | *
41 | * @param view
42 | * - View the user tapped.
43 | * @param x
44 | * - where the user tapped from the of the Drawable, as
45 | * percentage of the Drawable width.
46 | * @param y
47 | * - where the user tapped from the top of the Drawable, as
48 | * percentage of the Drawable height.
49 | */
50 | public void onPhotoTap(View view, float x, float y);
51 | }
52 |
53 | /**
54 | * Interface definition for a callback to be invoked when the ImageView is
55 | * tapped with a single tap.
56 | *
57 | * @author tomasz.zawada@gmail.com
58 | */
59 | public static interface OnViewTapListener {
60 | /**
61 | * A callback to receive where the user taps on a ImageView. You will
62 | * receive a callback if the user taps anywhere on the view, tapping on
63 | * 'whitespace' will not be ignored.
64 | *
65 | * @param view
66 | * - View the user tapped.
67 | * @param x
68 | * - where the user tapped from the left of the View.
69 | * @param y
70 | * - where the user tapped from the top of the View.
71 | */
72 | public void onViewTap(ZoomImageView zoomImageView, float x, float y);
73 | }
74 |
75 | /**
76 | *
77 | * The MultiGestureDetector manages the multi-finger pinch zoom, pan and tap
78 | *
79 | * @author tomasz.zawada@gmail.com
80 | *
81 | */
82 | private class MultiGestureDetector extends GestureDetector.SimpleOnGestureListener implements
83 | ScaleGestureDetector.OnScaleGestureListener {
84 | private final ScaleGestureDetector scaleGestureDetector;
85 | private final GestureDetector gestureDetector;
86 |
87 | private VelocityTracker velocityTracker;
88 | private boolean isDragging;
89 |
90 | private float lastTouchX;
91 | private float lastTouchY;
92 | private float lastPointerCount;
93 | private final float scaledTouchSlop;
94 | private final float scaledMinimumFlingVelocity;
95 |
96 | public MultiGestureDetector(Context context) {
97 | scaleGestureDetector = new ScaleGestureDetector(context, this);
98 |
99 | gestureDetector = new GestureDetector(context, this);
100 | gestureDetector.setOnDoubleTapListener(this);
101 |
102 | final ViewConfiguration configuration = ViewConfiguration.get(context);
103 | scaledMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
104 | scaledTouchSlop = configuration.getScaledTouchSlop();
105 | }
106 |
107 | public boolean isScaling() {
108 | return scaleGestureDetector.isInProgress();
109 | }
110 |
111 | public boolean onTouchEvent(MotionEvent event) {
112 | if (gestureDetector.onTouchEvent(event)) {
113 | return true;
114 | }
115 |
116 | scaleGestureDetector.onTouchEvent(event);
117 |
118 | /*
119 | * Get the center x, y of all the pointers
120 | */
121 | float x = 0, y = 0;
122 | final int pointerCount = event.getPointerCount();
123 | for (int i = 0; i < pointerCount; i++) {
124 | x += event.getX(i);
125 | y += event.getY(i);
126 | }
127 | x = x / pointerCount;
128 | y = y / pointerCount;
129 |
130 | /*
131 | * If the pointer count has changed cancel the drag
132 | */
133 | if (pointerCount != lastPointerCount) {
134 | isDragging = false;
135 | if (velocityTracker != null) {
136 | velocityTracker.clear();
137 | }
138 | lastTouchX = x;
139 | lastTouchY = y;
140 | }
141 | lastPointerCount = pointerCount;
142 |
143 | switch (event.getAction()) {
144 | case MotionEvent.ACTION_DOWN:
145 | if (velocityTracker == null) {
146 | velocityTracker = VelocityTracker.obtain();
147 | } else {
148 | velocityTracker.clear();
149 | }
150 | velocityTracker.addMovement(event);
151 |
152 | lastTouchX = x;
153 | lastTouchY = y;
154 | isDragging = false;
155 | break;
156 |
157 | case MotionEvent.ACTION_MOVE: {
158 | final float dx = x - lastTouchX, dy = y - lastTouchY;
159 |
160 | if (isDragging == false) {
161 | // Use Pythagoras to see if drag length is larger than
162 | // touch slop
163 | isDragging = Math.sqrt((dx * dx) + (dy * dy)) >= scaledTouchSlop;
164 | }
165 |
166 | if (isDragging) {
167 | if (getDrawable() != null) {
168 | suppMatrix.postTranslate(dx, dy);
169 | checkAndDisplayMatrix();
170 |
171 | /**
172 | * Here we decide whether to let the ImageView's
173 | * parent to start taking over the touch event.
174 | *
175 | * First we check whether this function is enabled.
176 | * We never want the parent to take over if we're
177 | * scaling. We then check the edge we're on, and the
178 | * direction of the scroll (i.e. if we're pulling
179 | * against the edge, aka 'overscrolling', let the
180 | * parent take over).
181 | */
182 | if (allowParentInterceptOnEdge && !multiGestureDetector.isScaling()) {
183 | if ((scrollEdge == EDGE_BOTH)
184 | || ((scrollEdge == EDGE_LEFT) && (dx >= 1f))
185 | || ((scrollEdge == EDGE_RIGHT) && (dx <= -1f))) {
186 |
187 | if (getParent() != null) {
188 | getParent().requestDisallowInterceptTouchEvent(false);
189 | }
190 | }
191 | }
192 | }
193 |
194 | lastTouchX = x;
195 | lastTouchY = y;
196 |
197 | if (velocityTracker != null) {
198 | velocityTracker.addMovement(event);
199 | }
200 | }
201 | break;
202 | }
203 | case MotionEvent.ACTION_UP: {
204 | if (isDragging) {
205 | lastTouchX = x;
206 | lastTouchY = y;
207 |
208 | // Compute velocity within the last 1000ms
209 | velocityTracker.addMovement(event);
210 | velocityTracker.computeCurrentVelocity(1000);
211 |
212 | final float vX = velocityTracker.getXVelocity(), vY = velocityTracker
213 | .getYVelocity();
214 |
215 | // If the velocity is greater than minVelocity perform
216 | // a fling
217 | if ((Math.max(Math.abs(vX), Math.abs(vY)) >= scaledMinimumFlingVelocity)
218 | && (getDrawable() != null)) {
219 | currentFlingRunnable = new FlingRunnable(getContext());
220 | currentFlingRunnable.fling(getWidth(), getHeight(), (int) -vX,
221 | (int) -vY);
222 | post(currentFlingRunnable);
223 | }
224 | }
225 | }
226 | case MotionEvent.ACTION_CANCEL:
227 | lastPointerCount = 0;
228 | if (velocityTracker != null) {
229 | velocityTracker.recycle();
230 | velocityTracker = null;
231 | }
232 | break;
233 | }
234 |
235 | return true;
236 | }
237 |
238 | @Override
239 | public boolean onScale(ScaleGestureDetector detector) {
240 | float scale = getScale();
241 | float scaleFactor = detector.getScaleFactor();
242 |
243 | if ((getDrawable() != null)
244 | && (!(((scale >= maxScale) && (scaleFactor > 1f)) || ((scale <= 0.75) && (scaleFactor < 1f))))) {
245 | suppMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(),
246 | detector.getFocusY());
247 | checkAndDisplayMatrix();
248 | }
249 |
250 | return true;
251 | }
252 |
253 | @Override
254 | public boolean onScaleBegin(ScaleGestureDetector detector) {
255 | return true;
256 | }
257 |
258 | @Override
259 | public void onScaleEnd(ScaleGestureDetector detector) {
260 | }
261 |
262 | @Override
263 | public boolean onDoubleTap(MotionEvent event) {
264 | try {
265 | float scale = getScale();
266 | float x = event.getX();
267 | float y = event.getY();
268 |
269 | if (scale < midScale) {
270 | post(new AnimatedZoomRunnable(scale, midScale, x, y));
271 | } else if ((scale >= midScale) && (scale < maxScale)) {
272 | post(new AnimatedZoomRunnable(scale, maxScale, x, y));
273 | } else {
274 | post(new AnimatedZoomRunnable(scale, minScale, x, y));
275 | }
276 | } catch (Exception e) {
277 | // Can sometimes happen when getX() and getY() is called
278 | }
279 |
280 | return true;
281 | }
282 |
283 | @Override
284 | public boolean onDoubleTapEvent(MotionEvent event) {
285 | // Wait for the confirmed onDoubleTap() instead
286 | return false;
287 | }
288 |
289 | @Override
290 | public boolean onSingleTapConfirmed(MotionEvent event) {
291 | if (photoTapListener != null) {
292 | final RectF displayRect = getDisplayRect();
293 |
294 | if (null != displayRect) {
295 | final float x = event.getX(), y = event.getY();
296 |
297 | // Check to see if the user tapped on the photo
298 | if (displayRect.contains(x, y)) {
299 |
300 | float xResult = (x - displayRect.left) / displayRect.width();
301 | float yResult = (y - displayRect.top) / displayRect.height();
302 |
303 | photoTapListener.onPhotoTap(ZoomImageView.this, xResult, yResult);
304 | return true;
305 | }
306 | }
307 | }
308 | if (viewTapListener != null) {
309 | viewTapListener.onViewTap(ZoomImageView.this, event.getX(), event.getY());
310 | }
311 |
312 | return false;
313 | }
314 |
315 | @Override
316 | public void onLongPress(MotionEvent e) {
317 | if (longClickListener != null) {
318 | longClickListener.onLongClick(ZoomImageView.this);
319 | }
320 | }
321 | }
322 |
323 | /**
324 | *
325 | * The ScrollerProxy encapsulates the Scroller and OverScroller classes.
326 | * OverScroller is available since API 9.
327 | *
328 | * @author tomasz.zawada@gmail.com
329 | *
330 | */
331 | @TargetApi(Build.VERSION_CODES.GINGERBREAD)
332 | private class ScrollerProxy {
333 |
334 | private boolean isOld;
335 | private Object scroller;
336 |
337 | public ScrollerProxy(Context context) {
338 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
339 | isOld = true;
340 | scroller = new Scroller(context);
341 | } else {
342 | isOld = false;
343 | scroller = new OverScroller(context);
344 | }
345 | }
346 |
347 | public boolean computeScrollOffset() {
348 | return isOld ? ((Scroller) scroller).computeScrollOffset() : ((OverScroller) scroller)
349 | .computeScrollOffset();
350 | }
351 |
352 | public void fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX,
353 | int minY, int maxY, int overX, int overY) {
354 |
355 | if (isOld) {
356 | ((Scroller) scroller).fling(startX, startY, velocityX, velocityY, minX, maxX, minY,
357 | maxY);
358 | } else {
359 | ((OverScroller) scroller).fling(startX, startY, velocityX, velocityY, minX, maxX,
360 | minY, maxY, overX, overY);
361 | }
362 | }
363 |
364 | public void forceFinished(boolean finished) {
365 | if (isOld) {
366 | ((Scroller) scroller).forceFinished(finished);
367 | } else {
368 | ((OverScroller) scroller).forceFinished(finished);
369 | }
370 | }
371 |
372 | public int getCurrX() {
373 | return isOld ? ((Scroller) scroller).getCurrX() : ((OverScroller) scroller).getCurrX();
374 | }
375 |
376 | public int getCurrY() {
377 | return isOld ? ((Scroller) scroller).getCurrY() : ((OverScroller) scroller).getCurrY();
378 | }
379 | }
380 |
381 | private static final int EDGE_NONE = -1;
382 | private static final int EDGE_LEFT = 0;
383 | private static final int EDGE_RIGHT = 1;
384 | private static final int EDGE_BOTH = 2;
385 |
386 | public static final float DEFAULT_MAX_SCALE = 3.0f;
387 | public static final float DEFAULT_MID_SCALE = 1.75f;
388 | public static final float DEFAULT_MIN_SCALE = 1f;
389 |
390 | private float minScale = DEFAULT_MIN_SCALE;
391 | private float midScale = DEFAULT_MID_SCALE;
392 | private float maxScale = DEFAULT_MAX_SCALE;
393 |
394 | private boolean allowParentInterceptOnEdge = true;
395 |
396 | private MultiGestureDetector multiGestureDetector;
397 |
398 | // These are set so we don't keep allocating them on the heap
399 | private final Matrix baseMatrix = new Matrix();
400 | private final Matrix drawMatrix = new Matrix();
401 | private final Matrix suppMatrix = new Matrix();
402 | private final RectF displayRect = new RectF();
403 | private final float[] matrixValues = new float[9];
404 |
405 | // Listeners
406 | private OnPhotoTapListener photoTapListener;
407 | private OnViewTapListener viewTapListener;
408 | private OnLongClickListener longClickListener;
409 |
410 | private int top, right, bottom, left;
411 | private FlingRunnable currentFlingRunnable;
412 | private int scrollEdge = EDGE_BOTH;
413 |
414 | private boolean isZoomEnabled;
415 | private ScaleType scaleType = ScaleType.FIT_CENTER;
416 |
417 | public ZoomImageView(Context context) {
418 | this(context, null);
419 | }
420 |
421 | public ZoomImageView(Context context, AttributeSet attr) {
422 | this(context, attr, 0);
423 | }
424 |
425 | public ZoomImageView(Context context, AttributeSet attr, int defStyle) {
426 | super(context, attr, defStyle);
427 |
428 | super.setScaleType(ScaleType.MATRIX);
429 |
430 | setOnTouchListener(this);
431 |
432 | multiGestureDetector = new MultiGestureDetector(context);
433 |
434 | setIsZoomEnabled(true);
435 | }
436 |
437 | /**
438 | * Gets the Display Rectangle of the currently displayed Drawable. The
439 | * Rectangle is relative to this View and includes all scaling and
440 | * translations.
441 | *
442 | * @return - RectF of Displayed Drawable
443 | */
444 | public final RectF getDisplayRect() {
445 | checkMatrixBounds();
446 | return getDisplayRect(getDisplayMatrix());
447 | }
448 |
449 | /**
450 | * @return The current minimum scale level. What this value represents
451 | * depends on the current {@link android.widget.ImageView.ScaleType}
452 | */
453 | public float getMinScale() {
454 | return minScale;
455 | }
456 |
457 | /**
458 | * Sets the minimum scale level. What this value represents depends on the
459 | * current {@link android.widget.ImageView.ScaleType}.
460 | */
461 | public void setMinScale(float minScale) {
462 | checkZoomLevels(minScale, midScale, maxScale);
463 | this.minScale = minScale;
464 | }
465 |
466 | /**
467 | * @return The current middle scale level. What this value represents
468 | * depends on the current {@link android.widget.ImageView.ScaleType}
469 | */
470 | public float getMidScale() {
471 | return midScale;
472 | }
473 |
474 | /**
475 | * Sets the middle scale level. What this value represents depends on the
476 | * current {@link android.widget.ImageView.ScaleType}.
477 | */
478 | public void setMidScale(float midScale) {
479 | checkZoomLevels(minScale, midScale, maxScale);
480 | this.midScale = midScale;
481 | }
482 |
483 | /**
484 | * @return The current maximum scale level. What this value represents
485 | * depends on the current {@link android.widget.ImageView.ScaleType}
486 | */
487 | public float getMaxScale() {
488 | return maxScale;
489 | }
490 |
491 | /**
492 | * Sets the maximum scale level. What this value represents depends on the
493 | * current {@link android.widget.ImageView.ScaleType}.
494 | */
495 | public void setMaxScale(float maxScale) {
496 | checkZoomLevels(minScale, midScale, maxScale);
497 | this.maxScale = maxScale;
498 | }
499 |
500 | /**
501 | * Returns the current scale value
502 | *
503 | * @return float - current scale value
504 | */
505 | public final float getScale() {
506 | suppMatrix.getValues(matrixValues);
507 | return matrixValues[Matrix.MSCALE_X];
508 | }
509 |
510 | /**
511 | * Return the current scale type in use by the ImageView.
512 | */
513 | @Override
514 | public final ScaleType getScaleType() {
515 | return scaleType;
516 | }
517 |
518 | /**
519 | * Controls how the image should be resized or moved to match the size of
520 | * the ImageView. Any scaling or panning will happen within the confines of
521 | * this {@link android.widget.ImageView.ScaleType}.
522 | *
523 | * @param scaleType
524 | * - The desired scaling mode.
525 | */
526 | @Override
527 | public final void setScaleType(ScaleType scaleType) {
528 | if (scaleType == ScaleType.MATRIX) {
529 | throw new IllegalArgumentException(scaleType.name()
530 | + " is not supported in ZoomImageView");
531 | }
532 |
533 | if (scaleType != this.scaleType) {
534 | this.scaleType = scaleType;
535 | update();
536 | }
537 | }
538 |
539 | /**
540 | * Returns true if the ZoomImageView is set to allow zooming of Photos.
541 | *
542 | * @return true if the ZoomImageView allows zooming.
543 | */
544 | public final boolean isZoomEnabled() {
545 | return isZoomEnabled;
546 | }
547 |
548 | /**
549 | * Allows you to enable/disable the zoom functionality on the ImageView.
550 | * When disable the ImageView reverts to using the FIT_CENTER matrix.
551 | *
552 | * @param isZoomEnabled
553 | * - Whether the zoom functionality is enabled.
554 | */
555 | public final void setIsZoomEnabled(boolean isZoomEnabled) {
556 | this.isZoomEnabled = isZoomEnabled;
557 | update();
558 | }
559 |
560 | /**
561 | * Whether to allow the ImageView's parent to intercept the touch event when
562 | * the photo is scroll to it's horizontal edge.
563 | */
564 | public void setAllowParentInterceptOnEdge(boolean allowParentInterceptOnEdge) {
565 | this.allowParentInterceptOnEdge = allowParentInterceptOnEdge;
566 | }
567 |
568 | @Override
569 | public void setImageBitmap(Bitmap bitmap) {
570 | super.setImageBitmap(bitmap);
571 | update();
572 | }
573 |
574 | @Override
575 | public void setImageDrawable(Drawable drawable) {
576 | super.setImageDrawable(drawable);
577 | update();
578 | }
579 |
580 | @Override
581 | public void setImageResource(int resId) {
582 | super.setImageResource(resId);
583 | update();
584 | }
585 |
586 | @Override
587 | public void setImageURI(Uri uri) {
588 | super.setImageURI(uri);
589 | update();
590 | }
591 |
592 | /**
593 | * Register a callback to be invoked when the Photo displayed by this view
594 | * is long-pressed.
595 | *
596 | * @param listener
597 | * - Listener to be registered.
598 | */
599 | @Override
600 | public final void setOnLongClickListener(OnLongClickListener listener) {
601 | longClickListener = listener;
602 | }
603 |
604 | /**
605 | * Register a callback to be invoked when the Photo displayed by this View
606 | * is tapped with a single tap.
607 | *
608 | * @param listener
609 | * - Listener to be registered.
610 | */
611 | public final void setOnPhotoTapListener(OnPhotoTapListener listener) {
612 | photoTapListener = listener;
613 | }
614 |
615 | /**
616 | * Register a callback to be invoked when the View is tapped with a single
617 | * tap.
618 | *
619 | * @param listener
620 | * - Listener to be registered.
621 | */
622 | public final void setOnViewTapListener(OnViewTapListener listener) {
623 | viewTapListener = listener;
624 | }
625 |
626 | @Override
627 | public final void onGlobalLayout() {
628 | if (isZoomEnabled) {
629 | final int top = getTop();
630 | final int right = getRight();
631 | final int bottom = getBottom();
632 | final int left = getLeft();
633 |
634 | /**
635 | * We need to check whether the ImageView's bounds have changed.
636 | * This would be easier if we targeted API 11+ as we could just use
637 | * View.OnLayoutChangeListener. Instead we have to replicate the
638 | * work, keeping track of the ImageView's bounds and then checking
639 | * if the values change.
640 | */
641 | if ((top != this.top) || (bottom != this.bottom) || (left != this.left)
642 | || (right != this.right)) {
643 | // Update our base matrix, as the bounds have changed
644 | updateBaseMatrix(getDrawable());
645 |
646 | // Update values as something has changed
647 | this.top = top;
648 | this.right = right;
649 | this.bottom = bottom;
650 | this.left = left;
651 | }
652 | }
653 | }
654 |
655 | @Override
656 | public final boolean onTouch(View v, MotionEvent ev) {
657 | boolean handled = false;
658 |
659 | if (isZoomEnabled) {
660 | switch (ev.getAction()) {
661 | case MotionEvent.ACTION_DOWN:
662 | // First, disable the Parent from intercepting the touch
663 | // event
664 | if (v.getParent() != null) {
665 | v.getParent().requestDisallowInterceptTouchEvent(true);
666 | }
667 |
668 | // If we're flinging, and the user presses down, cancel
669 | // fling
670 | if (currentFlingRunnable != null) {
671 | currentFlingRunnable.cancelFling();
672 | currentFlingRunnable = null;
673 | }
674 | break;
675 |
676 | case MotionEvent.ACTION_CANCEL:
677 | case MotionEvent.ACTION_UP:
678 | // If the user has zoomed less than min scale, zoom back
679 | // to min scale
680 | if (getScale() < minScale) {
681 | RectF rect = getDisplayRect();
682 | if (null != rect) {
683 | v.post(new AnimatedZoomRunnable(getScale(), minScale, rect.centerX(),
684 | rect.centerY()));
685 | handled = true;
686 | }
687 | }
688 | break;
689 | }
690 |
691 | // Finally, try the scale/drag/tap detector
692 | if ((multiGestureDetector != null) && multiGestureDetector.onTouchEvent(ev)) {
693 | handled = true;
694 | }
695 | }
696 |
697 | return handled;
698 | }
699 |
700 | @Override
701 | protected void onAttachedToWindow() {
702 | super.onAttachedToWindow();
703 |
704 | getViewTreeObserver().addOnGlobalLayoutListener(this);
705 | }
706 |
707 | @SuppressWarnings("deprecation")
708 | @Override
709 | protected void onDetachedFromWindow() {
710 | super.onDetachedFromWindow();
711 |
712 | getViewTreeObserver().removeGlobalOnLayoutListener(this);
713 | }
714 |
715 | protected Matrix getDisplayMatrix() {
716 | drawMatrix.set(baseMatrix);
717 | drawMatrix.postConcat(suppMatrix);
718 | return drawMatrix;
719 | }
720 |
721 | private final void update() {
722 | if (isZoomEnabled) {
723 | super.setScaleType(ScaleType.MATRIX);
724 | updateBaseMatrix(getDrawable());
725 | } else {
726 | resetMatrix();
727 | }
728 | }
729 |
730 | /**
731 | * Helper method that simply checks the Matrix, and then displays the result
732 | */
733 | private void checkAndDisplayMatrix() {
734 | checkMatrixBounds();
735 | setImageMatrix(getDisplayMatrix());
736 | }
737 |
738 | private void checkMatrixBounds() {
739 | final RectF rect = getDisplayRect(getDisplayMatrix());
740 | if (null == rect) {
741 | return;
742 | }
743 |
744 | final float height = rect.height(), width = rect.width();
745 | float deltaX = 0, deltaY = 0;
746 |
747 | final int viewHeight = getHeight();
748 | if (height <= viewHeight) {
749 | switch (scaleType) {
750 | case FIT_START:
751 | deltaY = -rect.top;
752 | break;
753 | case FIT_END:
754 | deltaY = viewHeight - height - rect.top;
755 | break;
756 | default:
757 | deltaY = ((viewHeight - height) / 2) - rect.top;
758 | break;
759 | }
760 | } else if (rect.top > 0) {
761 | deltaY = -rect.top;
762 | } else if (rect.bottom < viewHeight) {
763 | deltaY = viewHeight - rect.bottom;
764 | }
765 |
766 | final int viewWidth = getWidth();
767 | if (width <= viewWidth) {
768 | switch (scaleType) {
769 | case FIT_START:
770 | deltaX = -rect.left;
771 | break;
772 | case FIT_END:
773 | deltaX = viewWidth - width - rect.left;
774 | break;
775 | default:
776 | deltaX = ((viewWidth - width) / 2) - rect.left;
777 | break;
778 | }
779 | scrollEdge = EDGE_BOTH;
780 | } else if (rect.left > 0) {
781 | scrollEdge = EDGE_LEFT;
782 | deltaX = -rect.left;
783 | } else if (rect.right < viewWidth) {
784 | deltaX = viewWidth - rect.right;
785 | scrollEdge = EDGE_RIGHT;
786 | } else {
787 | scrollEdge = EDGE_NONE;
788 | }
789 |
790 | // Finally actually translate the matrix
791 | suppMatrix.postTranslate(deltaX, deltaY);
792 | }
793 |
794 | /**
795 | * Helper method that maps the supplied Matrix to the current Drawable
796 | *
797 | * @param matrix
798 | * - Matrix to map Drawable against
799 | * @return RectF - Displayed Rectangle
800 | */
801 | private RectF getDisplayRect(Matrix matrix) {
802 | Drawable d = getDrawable();
803 | if (null != d) {
804 | displayRect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
805 | matrix.mapRect(displayRect);
806 | return displayRect;
807 | }
808 |
809 | return null;
810 | }
811 |
812 | /**
813 | * Resets the Matrix back to FIT_CENTER, and then displays it.s
814 | */
815 | private void resetMatrix() {
816 | suppMatrix.reset();
817 | setImageMatrix(getDisplayMatrix());
818 | checkMatrixBounds();
819 | }
820 |
821 | /**
822 | * Calculate Matrix for FIT_CENTER
823 | *
824 | * @param d
825 | * - Drawable being displayed
826 | */
827 | private void updateBaseMatrix(Drawable d) {
828 | if (null == d) {
829 | return;
830 | }
831 |
832 | final float viewWidth = getWidth();
833 | final float viewHeight = getHeight();
834 | final int drawableWidth = d.getIntrinsicWidth();
835 | final int drawableHeight = d.getIntrinsicHeight();
836 |
837 | baseMatrix.reset();
838 |
839 | final float widthScale = viewWidth / drawableWidth;
840 | final float heightScale = viewHeight / drawableHeight;
841 |
842 | if (scaleType == ScaleType.CENTER) {
843 | baseMatrix.postTranslate((viewWidth - drawableWidth) / 2F,
844 | (viewHeight - drawableHeight) / 2F);
845 |
846 | } else if (scaleType == ScaleType.CENTER_CROP) {
847 | float scale = Math.max(widthScale, heightScale);
848 | baseMatrix.postScale(scale, scale);
849 | baseMatrix.postTranslate((viewWidth - (drawableWidth * scale)) / 2F,
850 | (viewHeight - (drawableHeight * scale)) / 2F);
851 |
852 | } else if (scaleType == ScaleType.CENTER_INSIDE) {
853 | float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
854 | baseMatrix.postScale(scale, scale);
855 | baseMatrix.postTranslate((viewWidth - (drawableWidth * scale)) / 2F,
856 | (viewHeight - (drawableHeight * scale)) / 2F);
857 |
858 | } else {
859 | RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
860 | RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);
861 |
862 | switch (scaleType) {
863 | case FIT_CENTER:
864 | baseMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER);
865 | break;
866 |
867 | case FIT_START:
868 | baseMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.START);
869 | break;
870 |
871 | case FIT_END:
872 | baseMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.END);
873 | break;
874 |
875 | case FIT_XY:
876 | baseMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.FILL);
877 | break;
878 |
879 | default:
880 | break;
881 | }
882 | }
883 |
884 | resetMatrix();
885 | }
886 |
887 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
888 | private void postOnAnimation(View view, Runnable runnable) {
889 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
890 | view.postOnAnimation(runnable);
891 | } else {
892 | view.postDelayed(runnable, 16);
893 | }
894 | }
895 |
896 | private void checkZoomLevels(float minZoom, float midZoom, float maxZoom) {
897 | if (minZoom >= midZoom) {
898 | throw new IllegalArgumentException("MinZoom should be less than MidZoom");
899 | } else if (midZoom >= maxZoom) {
900 | throw new IllegalArgumentException("MidZoom should be less than MaxZoom");
901 | }
902 | }
903 |
904 | private class AnimatedZoomRunnable implements Runnable {
905 | // These are 'postScale' values, means they're compounded each iteration
906 | static final float ANIMATION_SCALE_PER_ITERATION_IN = 1.07f;
907 | static final float ANIMATION_SCALE_PER_ITERATION_OUT = 0.93f;
908 |
909 | private final float focalX, focalY;
910 | private final float targetZoom;
911 | private final float deltaScale;
912 |
913 | public AnimatedZoomRunnable(final float currentZoom, final float targetZoom,
914 | final float focalX, final float focalY) {
915 | this.targetZoom = targetZoom;
916 | this.focalX = focalX;
917 | this.focalY = focalY;
918 |
919 | if (currentZoom < targetZoom) {
920 | deltaScale = ANIMATION_SCALE_PER_ITERATION_IN;
921 | } else {
922 | deltaScale = ANIMATION_SCALE_PER_ITERATION_OUT;
923 | }
924 | }
925 |
926 | public void run() {
927 | suppMatrix.postScale(deltaScale, deltaScale, focalX, focalY);
928 | checkAndDisplayMatrix();
929 |
930 | final float currentScale = getScale();
931 |
932 | if (((deltaScale > 1f) && (currentScale < targetZoom))
933 | || ((deltaScale < 1f) && (targetZoom < currentScale))) {
934 | // We haven't hit our target scale yet, so post ourselves
935 | // again
936 | postOnAnimation(ZoomImageView.this, this);
937 |
938 | } else {
939 | // We've scaled past our target zoom, so calculate the
940 | // necessary scale so we're back at target zoom
941 | final float delta = targetZoom / currentScale;
942 | suppMatrix.postScale(delta, delta, focalX, focalY);
943 | checkAndDisplayMatrix();
944 | }
945 | }
946 | }
947 |
948 | private class FlingRunnable implements Runnable {
949 | private final ScrollerProxy scroller;
950 | private int currentX, currentY;
951 |
952 | public FlingRunnable(Context context) {
953 | scroller = new ScrollerProxy(context);
954 | }
955 |
956 | public void cancelFling() {
957 | scroller.forceFinished(true);
958 | }
959 |
960 | public void fling(int viewWidth, int viewHeight, int velocityX, int velocityY) {
961 | final RectF rect = getDisplayRect();
962 | if (null == rect) {
963 | return;
964 | }
965 |
966 | final int startX = Math.round(-rect.left);
967 | final int minX, maxX, minY, maxY;
968 |
969 | if (viewWidth < rect.width()) {
970 | minX = 0;
971 | maxX = Math.round(rect.width() - viewWidth);
972 | } else {
973 | minX = maxX = startX;
974 | }
975 |
976 | final int startY = Math.round(-rect.top);
977 | if (viewHeight < rect.height()) {
978 | minY = 0;
979 | maxY = Math.round(rect.height() - viewHeight);
980 | } else {
981 | minY = maxY = startY;
982 | }
983 |
984 | currentX = startX;
985 | currentY = startY;
986 |
987 | // If we actually can move, fling the scroller
988 | if ((startX != maxX) || (startY != maxY)) {
989 | scroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY, 0, 0);
990 | }
991 | }
992 |
993 | @Override
994 | public void run() {
995 | if (scroller.computeScrollOffset()) {
996 | final int newX = scroller.getCurrX();
997 | final int newY = scroller.getCurrY();
998 |
999 | suppMatrix.postTranslate(currentX - newX, currentY - newY);
1000 | setImageMatrix(getDisplayMatrix());
1001 |
1002 | currentX = newX;
1003 | currentY = newY;
1004 |
1005 | // Post On animation
1006 | postOnAnimation(ZoomImageView.this, this);
1007 | }
1008 | }
1009 | }
1010 | }
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_right_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_right_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/about.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/about_activity.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
13 |
14 |
15 |
16 |
22 |
23 |
31 |
32 |
40 |
41 |
42 |
43 |
48 |
49 |
55 |
56 |
62 |
63 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/detail_activity_gank.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
13 |
14 |
21 |
22 |
28 |
29 |
35 |
36 |
37 |
38 |
39 |
40 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/detail_view_holder_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
25 |
26 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/home_activity_gank.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
28 |
29 |
30 |
31 |
32 |
44 |
45 |
53 |
54 |
63 |
64 |
71 |
72 |
73 |
84 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_activity_gank_list.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
15 |
16 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_view_holder_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
23 |
24 |
30 |
31 |
37 |
38 |
44 |
45 |
49 |
50 |
56 |
57 |
63 |
64 |
65 |
66 |
67 |
68 |
75 |
76 |
77 |
88 |
89 |
93 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/picture_activity.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_toolbar.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/web_activity_gank.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
16 |
17 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_gank.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_picture.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_share.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_web.xml:
--------------------------------------------------------------------------------
1 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/gank_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Veaer/Gank-Veaer/f128df769d8cda75ba1e4c3ec3aa58c6e685f002/app/src/main/res/mipmap-hdpi/gank_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/gank_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Veaer/Gank-Veaer/f128df769d8cda75ba1e4c3ec3aa58c6e685f002/app/src/main/res/mipmap-mdpi/gank_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/gank_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Veaer/Gank-Veaer/f128df769d8cda75ba1e4c3ec3aa58c6e685f002/app/src/main/res/mipmap-xhdpi/gank_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_arrow_back_white_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Veaer/Gank-Veaer/f128df769d8cda75ba1e4c3ec3aa58c6e685f002/app/src/main/res/mipmap-xhdpi/ic_arrow_back_white_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Veaer/Gank-Veaer/f128df769d8cda75ba1e4c3ec3aa58c6e685f002/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_refresh_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Veaer/Gank-Veaer/f128df769d8cda75ba1e4c3ec3aa58c6e685f002/app/src/main/res/mipmap-xhdpi/ic_refresh_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_save_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Veaer/Gank-Veaer/f128df769d8cda75ba1e4c3ec3aa58c6e685f002/app/src/main/res/mipmap-xhdpi/ic_save_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_share_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Veaer/Gank-Veaer/f128df769d8cda75ba1e4c3ec3aa58c6e685f002/app/src/main/res/mipmap-xhdpi/ic_share_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/gank_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Veaer/Gank-Veaer/f128df769d8cda75ba1e4c3ec3aa58c6e685f002/app/src/main/res/mipmap-xxhdpi/gank_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v19/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 | 25dp
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/android_material_design_colours.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 | #fde0dc
9 | #f9bdbb
10 | #f69988
11 | #f36c60
12 | #e84e40
13 | #e51c23
14 | #dd191d
15 | #d01716
16 | #c41411
17 | #b0120a
18 | #ff7997
19 | #ff5177
20 | #ff2d6f
21 | #e00032
22 |
23 |
24 | #fce4ec
25 | #f8bbd0
26 | #f48fb1
27 | #f06292
28 | #ec407a
29 | #e91e63
30 | #d81b60
31 | #c2185b
32 | #ad1457
33 | #880e4f
34 | #ff80ab
35 | #ff4081
36 | #f50057
37 | #c51162
38 |
39 |
40 | #f3e5f5
41 | #e1bee7
42 | #ce93d8
43 | #ba68c8
44 | #ab47bc
45 | #9c27b0
46 | #8e24aa
47 | #7b1fa2
48 | #6a1b9a
49 | #4a148c
50 | #ea80fc
51 | #e040fb
52 | #d500f9
53 | #aa00ff
54 |
55 |
56 | #ede7f6
57 | #d1c4e9
58 | #b39ddb
59 | #9575cd
60 | #7e57c2
61 | #673ab7
62 | #5e35b1
63 | #512da8
64 | #4527a0
65 | #311b92
66 | #b388ff
67 | #7c4dff
68 | #651fff
69 | #6200ea
70 |
71 |
72 | #e8eaf6
73 | #c5cae9
74 | #9fa8da
75 | #7986cb
76 | #5c6bc0
77 | #3f51b5
78 | #3949ab
79 | #303f9f
80 | #283593
81 | #1a237e
82 | #8c9eff
83 | #536dfe
84 | #3d5afe
85 | #304ffe
86 |
87 |
88 | #e7e9fd
89 | #d0d9ff
90 | #afbfff
91 | #91a7ff
92 | #738ffe
93 | #5677fc
94 | #4e6cef
95 | #455ede
96 | #3b50ce
97 | #2a36b1
98 | #a6baff
99 | #6889ff
100 | #4d73ff
101 | #4d69ff
102 |
103 |
104 | #e1f5fe
105 | #b3e5fc
106 | #81d4fa
107 | #4fc3f7
108 | #29b6f6
109 | #03a9f4
110 | #039be5
111 | #0288d1
112 | #0277bd
113 | #01579b
114 | #80d8ff
115 | #40c4ff
116 | #00b0ff
117 | #0091ea
118 |
119 |
120 | #e0f7fa
121 | #b2ebf2
122 | #80deea
123 | #4dd0e1
124 | #26c6da
125 | #00bcd4
126 | #00acc1
127 | #0097a7
128 | #00838f
129 | #006064
130 | #84ffff
131 | #18ffff
132 | #00e5ff
133 | #00b8d4
134 |
135 |
136 | #e0f2f1
137 | #b2dfdb
138 | #80cbc4
139 | #4db6ac
140 | #26a69a
141 | #009688
142 | #00897b
143 | #00796b
144 | #00695c
145 | #004d40
146 | #a7ffeb
147 | #64ffda
148 | #1de9b6
149 | #00bfa5
150 |
151 |
152 | #d0f8ce
153 | #a3e9a4
154 | #72d572
155 | #42bd41
156 | #2baf2b
157 | #259b24
158 | #0a8f08
159 | #0a7e07
160 | #056f00
161 | #0d5302
162 | #a2f78d
163 | #5af158
164 | #14e715
165 | #12c700
166 |
167 |
168 | #f1f8e9
169 | #dcedc8
170 | #c5e1a5
171 | #aed581
172 | #9ccc65
173 | #8bc34a
174 | #7cb342
175 | #689f38
176 | #558b2f
177 | #33691e
178 | #ccff90
179 | #b2ff59
180 | #76ff03
181 | #64dd17
182 |
183 |
184 | #f9fbe7
185 | #f0f4c3
186 | #e6ee9c
187 | #dce775
188 | #d4e157
189 | #cddc39
190 | #c0ca33
191 | #afb42b
192 | #9e9d24
193 | #827717
194 | #f4ff81
195 | #eeff41
196 | #c6ff00
197 | #aeea00
198 |
199 |
200 | #fffde7
201 | #fff9c4
202 | #fff59d
203 | #fff176
204 | #ffee58
205 | #ffeb3b
206 | #fdd835
207 | #fbc02d
208 | #f9a825
209 | #f57f17
210 | #ffff8d
211 | #ffff00
212 | #ffea00
213 | #ffd600
214 |
215 |
216 | #fff8e1
217 | #ffecb3
218 | #ffe082
219 | #ffd54f
220 | #ffca28
221 | #ffc107
222 | #ffb300
223 | #ffa000
224 | #ff8f00
225 | #ff6f00
226 | #ffe57f
227 | #ffd740
228 | #ffc400
229 | #ffab00
230 |
231 |
232 | #fff3e0
233 | #ffe0b2
234 | #ffcc80
235 | #ffb74d
236 | #ffa726
237 | #ff9800
238 | #fb8c00
239 | #f57c00
240 | #ef6c00
241 | #e65100
242 | #ffd180
243 | #ffab40
244 | #ff9100
245 | #ff6d00
246 |
247 |
248 | #fbe9e7
249 | #ffccbc
250 | #ffab91
251 | #ff8a65
252 | #ff7043
253 | #ff5722
254 | #f4511e
255 | #e64a19
256 | #d84315
257 | #bf360c
258 | #ff9e80
259 | #ff6e40
260 | #ff3d00
261 | #dd2c00
262 |
263 |
264 | #efebe9
265 | #d7ccc8
266 | #bcaaa4
267 | #a1887f
268 | #8d6e63
269 | #795548
270 | #6d4c41
271 | #5d4037
272 | #4e342e
273 | #3e2723
274 |
275 |
276 | #fafafa
277 | #f5f5f5
278 | #eeeeee
279 | #e0e0e0
280 | #bdbdbd
281 | #9e9e9e
282 | #757575
283 | #616161
284 | #424242
285 | #212121
286 | #000000
287 | #ffffff
288 |
289 |
290 | #eceff1
291 | #cfd8dc
292 | #b0bec5
293 | #90a4ae
294 | #78909c
295 | #607d8b
296 | #546e7a
297 | #455a64
298 | #37474f
299 | #263238
300 |
301 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #050203
4 | #2d1e1b
5 | #231714
6 |
7 | #5a5350
8 | #242527
9 |
10 |
11 | #e91e63
12 | #00b0ff
13 | @color/theme_primary
14 | @color/theme_primary_darker
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 0dp
6 | 15dp
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 干客
3 |
4 | Hello world!
5 | ★
6 | -->去看视频~
7 | 查看往期
8 | 分享
9 | 刷新
10 | 在其他浏览器打开
11 | 未找到相关应用
12 | 保存到本地?
13 | 保存
14 | 保存成功
15 | 图片已保存至 %s 文件夹
16 | 我发现了一款非常"有用"的App「干客」,每天一张精选妹纸图、一个精选小视频,一篇程序猿干货,完全开源不收费,太赞了! 推荐~:http://fir.im/gankapp
17 | 我发现了一篇好文章
18 | 来自干客,下载:http://fir.im/gankapp
19 | 每天一张精选妹纸图、一个精选小视频(视频源地址播放,因为视频来源包含各大平台。。。着实不好统一播放器。。。),一篇程序猿精选干货。\n\n数据内容来源于代码家的 http://gank.io ,Veaer 完成 Android 端的开发和设计, 非常感谢drakeet。\n\n我的 GitHub: https://github.com/Veaer\n\n完全开源,如果你觉得不错,可以帮忙分享给你更多的朋友,这是我们最大的动力和支持,或者请我喝一杯咖啡(所谓的捐赠或打赏QAQ),非常感谢!\n\n支付宝: veaer.king@gmail.com (点击复制到剪贴板)
20 | 关于开发者
21 | 已复制到剪贴板
22 | veaer.king@gmail.com
23 | 貌似网络出了一点问题,快喝口水冷静一下😂
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | apply from: "config.gradle"
3 |
4 | buildscript {
5 | repositories {
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:1.5.0'
10 | classpath 'me.tatarka:gradle-retrolambda:3.2.0'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | maven { url "https://jitpack.io" }
21 | maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Veaer
3 | *
4 | * This file is part of Gank
5 | *
6 | * Gank is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Gank is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Gank. If not, see .
18 | */
19 |
20 | ext {
21 |
22 | android = [
23 | compileSdkVersion: 23,
24 | buildToolsVersion: "23.0.2",
25 | applicationId : "com.veaer.gank",
26 | minSdkVersion : 14,
27 | targetSdkVersion : 22,
28 | versionCode : 1,
29 | versionName : "1.0.0"
30 | ]
31 | dependencies = [
32 | "appcompat-v7" : "com.android.support:appcompat-v7:23.1.1",
33 | "design" : "com.android.support:design:23.1.1",
34 | "recyclerview-v7" : "com.android.support:recyclerview-v7:23.1.1",
35 | "okhttp" : "com.squareup.okhttp:okhttp:2.3.0",
36 | "retrofit" : "com.squareup.retrofit:retrofit:1.9.0",
37 | "rxandroid" : "io.reactivex:rxandroid:1.0.1",
38 | "butterknife" : "com.jakewharton:butterknife:7.0.1",
39 | "umeng-analytics" : "com.umeng.analytics:analytics:latest.integration",
40 | "glide" : "com.github.bumptech.glide:glide:3.6.1"
41 | ]
42 | }
43 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Veaer/Gank-Veaer/f128df769d8cda75ba1e4c3ec3aa58c6e685f002/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Aug 15 16:45:34 CST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------