Full Code of zzhoujay/Gank4Android for AI

master d052b79c7c86 cached
110 files
268.2 KB
71.7k tokens
128 symbols
1 requests
Download .txt
Showing preview only (302K chars total). Download the full file or copy to clipboard to get everything.
Repository: zzhoujay/Gank4Android
Branch: master
Commit: d052b79c7c86
Files: 110
Total size: 268.2 KB

Directory structure:
gitextract_8uf00tm3/

├── .gitignore
├── LICENSE
├── README.md
├── app/
│   ├── .gitignore
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src/
│       ├── androidTest/
│       │   └── java/
│       │       └── zhou/
│       │           └── gank/
│       │               └── io/
│       │                   └── ApplicationTest.java
│       └── main/
│           ├── AndroidManifest.xml
│           ├── groovy/
│           │   └── zhou/
│           │       └── gank/
│           │           └── io/
│           │               ├── App.groovy
│           │               ├── MainActivity.groovy
│           │               ├── comment/
│           │               │   └── Config.groovy
│           │               ├── data/
│           │               │   ├── CollectProvider.groovy
│           │               │   ├── DataManager.groovy
│           │               │   ├── DataProvider.groovy
│           │               │   ├── RandomProvider.groovy
│           │               │   ├── TimeProvider.groovy
│           │               │   └── TypeProvider.groovy
│           │               ├── database/
│           │               │   └── DatabaseManager.groovy
│           │               ├── model/
│           │               │   ├── BaseResult.groovy
│           │               │   ├── Bookmark.groovy
│           │               │   ├── Gank.groovy
│           │               │   ├── GankDaily.groovy
│           │               │   ├── Result.groovy
│           │               │   └── ResultDaily.groovy
│           │               ├── net/
│           │               │   └── NetworkManager.groovy
│           │               ├── ui/
│           │               │   ├── activity/
│           │               │   │   ├── CollectActivity.groovy
│           │               │   │   ├── DailyActivity.groovy
│           │               │   │   ├── HomeActivity.groovy
│           │               │   │   ├── ImageGalleryActivity.groovy
│           │               │   │   ├── SettingActivity.groovy
│           │               │   │   ├── TabActivity.groovy
│           │               │   │   ├── ToolbarActivity.groovy
│           │               │   │   └── WebActivity.groovy
│           │               │   ├── adapter/
│           │               │   │   ├── BaseAdapter.groovy
│           │               │   │   ├── DailyAdapter.groovy
│           │               │   │   ├── GankAdapter.groovy
│           │               │   │   ├── ImageAdapter.groovy
│           │               │   │   └── ImageGalleryAdapter.groovy
│           │               │   ├── dialog/
│           │               │   │   └── InfoDialog.groovy
│           │               │   ├── fragment/
│           │               │   │   ├── AdvanceFragment.groovy
│           │               │   │   ├── BaseFragment.groovy
│           │               │   │   ├── DailyFragment.groovy
│           │               │   │   ├── GankFragment.groovy
│           │               │   │   ├── ImageFragment.groovy
│           │               │   │   ├── ImageGalleryFragment.groovy
│           │               │   │   ├── ImagePageFragment.groovy
│           │               │   │   ├── SettingFragment.groovy
│           │               │   │   └── WebFragment.groovy
│           │               │   └── weiget/
│           │               │       ├── SwipeToRefreshLayout.groovy
│           │               │       ├── TouchImageView.java
│           │               │       └── URLSpanNoUnderline.groovy
│           │               └── util/
│           │                   ├── FileKit.java
│           │                   ├── HashKit.java
│           │                   ├── JsonKit.groovy
│           │                   ├── LogKit.java
│           │                   ├── NetworkKit.groovy
│           │                   ├── Notifier.groovy
│           │                   ├── NumKit.groovy
│           │                   ├── Pageable.groovy
│           │                   ├── TextKit.groovy
│           │                   └── TimeKit.groovy
│           └── res/
│               ├── drawable/
│               │   ├── ic_bookmark_48px.xml
│               │   ├── ic_cloud_off_48px.xml
│               │   ├── ic_cloud_queue_48px.xml
│               │   ├── ic_dashboard_48px.xml
│               │   ├── ic_event_48px.xml
│               │   ├── ic_extension_48px.xml
│               │   ├── ic_favorite_white_48px.xml
│               │   ├── ic_info_48px.xml
│               │   ├── ic_insert_emoticon_48px.xml
│               │   ├── ic_menu_white_48px.xml
│               │   ├── ic_refresh_48px.xml
│               │   ├── ic_settings_black_48px.xml
│               │   └── ic_view_module_48px.xml
│               ├── layout/
│               │   ├── activity_compat.xml
│               │   ├── activity_home.xml
│               │   ├── activity_main.xml
│               │   ├── activity_tab.xml
│               │   ├── activity_toolbar.xml
│               │   ├── dialog_text.xml
│               │   ├── fragment_daily.xml
│               │   ├── fragment_image_page.xml
│               │   ├── fragment_recyler_view.xml
│               │   ├── fragment_viewpager.xml
│               │   ├── fragment_web.xml
│               │   ├── item_daily.xml
│               │   ├── item_gank.xml
│               │   ├── item_image.xml
│               │   ├── layout_gallery.xml
│               │   ├── layout_more.xml
│               │   └── nav_header.xml
│               ├── menu/
│               │   ├── drawer_view.xml
│               │   ├── menu_pop.xml
│               │   ├── menu_pop_add.xml
│               │   ├── menu_pop_remove.xml
│               │   └── menu_web.xml
│               ├── values/
│               │   ├── colors.xml
│               │   ├── dimens.xml
│               │   ├── strings.xml
│               │   └── styles.xml
│               ├── values-en/
│               │   └── strings.xml
│               ├── values-v21/
│               │   └── styles.xml
│               └── xml/
│                   └── setting.xml
├── build.gradle
├── gradle/
│   └── wrapper/
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
.gradle
/local.properties
.DS_Store
/build
/captures

.idea

*.iml

# built application files
*.apk
*.ap_

!/apk/app-release*

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Eclipse project files
.classpath
.project

# Proguard folder generated by Eclipse
proguard/

# Intellij project files
*.ipr
*.iws


================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by the copyright
owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all other entities
that control, are controlled by, or are under common control with that entity.
For the purposes of this definition, "control" means (i) the power, direct or
indirect, to cause the direction or management of such entity, whether by
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity exercising
permissions granted by this License.

"Source" form shall mean the preferred form for making modifications, including
but not limited to software source code, documentation source, and configuration
files.

"Object" form shall mean any form resulting from mechanical transformation or
translation of a Source form, including but not limited to compiled object code,
generated documentation, and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or Object form, made
available under the License, as indicated by a copyright notice that is included
in or attached to the work (an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object form, that
is based on (or derived from) the Work and for which the editorial revisions,
annotations, elaborations, or other modifications represent, as a whole, an
original work of authorship. For the purposes of this License, Derivative Works
shall not include works that remain separable from, or merely link (or bind by
name) to the interfaces of, the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including the original version
of the Work and any modifications or additions to that Work or Derivative Works
thereof, that is intentionally submitted to Licensor for inclusion in the Work
by the copyright owner or by an individual or Legal Entity authorized to submit
on behalf of the copyright owner. For the purposes of this definition,
"submitted" means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems, and
issue tracking systems that are managed by, or on behalf of, the Licensor for
the purpose of discussing and improving the Work, but excluding communication
that is conspicuously marked or otherwise designated in writing by the copyright
owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
of whom a Contribution has been received by Licensor and subsequently
incorporated within the Work.

2. Grant of Copyright License.

Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the Work and such
Derivative Works in Source or Object form.

3. Grant of Patent License.

Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to make, have
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
such license applies only to those patent claims licensable by such Contributor
that are necessarily infringed by their Contribution(s) alone or by combination
of their Contribution(s) with the Work to which such Contribution(s) was
submitted. If You institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
Contribution incorporated within the Work constitutes direct or contributory
patent infringement, then any patent licenses granted to You under this License
for that Work shall terminate as of the date such litigation is filed.

4. Redistribution.

You may reproduce and distribute copies of the Work or Derivative Works thereof
in any medium, with or without modifications, and in Source or Object form,
provided that You meet the following conditions:

You must give any other recipients of the Work or Derivative Works a copy of
this License; and
You must cause any modified files to carry prominent notices stating that You
changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute,
all copyright, patent, trademark, and attribution notices from the Source form
of the Work, excluding those notices that do not pertain to any part of the
Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any
Derivative Works that You distribute must include a readable copy of the
attribution notices contained within such NOTICE file, excluding those notices
that do not pertain to any part of the Derivative Works, in at least one of the
following places: within a NOTICE text file distributed as part of the
Derivative Works; within the Source form or documentation, if provided along
with the Derivative Works; or, within a display generated by the Derivative
Works, if and wherever such third-party notices normally appear. The contents of
the NOTICE file are for informational purposes only and do not modify the
License. You may add Your own attribution notices within Derivative Works that
You distribute, alongside or as an addendum to the NOTICE text from the Work,
provided that such additional attribution notices cannot be construed as
modifying the License.
You may add Your own copyright statement to Your modifications and may provide
additional or different license terms and conditions for use, reproduction, or
distribution of Your modifications, or for any such Derivative Works as a whole,
provided Your use, reproduction, and distribution of the Work otherwise complies
with the conditions stated in this License.

5. Submission of Contributions.

Unless You explicitly state otherwise, any Contribution intentionally submitted
for inclusion in the Work by You to the Licensor shall be under the terms and
conditions of this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify the terms of
any separate license agreement you may have executed with Licensor regarding
such Contributions.

6. Trademarks.

This License does not grant permission to use the trade names, trademarks,
service marks, or product names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the NOTICE file.

7. Disclaimer of Warranty.

Unless required by applicable law or agreed to in writing, Licensor provides the
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
including, without limitation, any warranties or conditions of TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
solely responsible for determining the appropriateness of using or
redistributing the Work and assume any risks associated with Your exercise of
permissions under this License.

8. Limitation of Liability.

In no event and under no legal theory, whether in tort (including negligence),
contract, or otherwise, unless required by applicable law (such as deliberate
and grossly negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special, incidental,
or consequential damages of any character arising as a result of this License or
out of the use or inability to use the Work (including but not limited to
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
any and all other commercial damages or losses), even if such Contributor has
been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability.

While redistributing the Work or Derivative Works thereof, You may choose to
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
other liability obligations and/or rights consistent with this License. However,
in accepting such obligations, You may act only on Your own behalf and on Your
sole responsibility, not on behalf of any other Contributor, and only if You
agree to indemnify, defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason of your
accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work

To apply the Apache License to your work, attach the following boilerplate
notice, with the fields enclosed by brackets "{}" replaced with your own
identifying information. (Don't include the brackets!) The text should be
enclosed in the appropriate comment syntax for the file format. We also
recommend that a file or class name and description of purpose be included on
the same "printed page" as the copyright notice for easier identification within
third-party archives.

   Copyright 2015 zzhoujay

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

================================================
FILE: README.md
================================================
#Gank4Android

> Deprecated 推荐使用更加简介的[DailyGank](https://github.com/zzhoujay/DailyGank)

> 使用`Groovy`开发的`Gank.IO` `Android`客户端
>
> 遵循Google `Material Design`设计原则

### 提示

由于Groovy的效率问题,和由于Groovy引入的一系列问题,本项目将不再推荐使用,推荐使用[DailyGank](https://github.com/zzhoujay/DailyGank)来阅读每天的干货,DailyGank使用Kotlin开发,
并且设计得十分的简洁,比本项目更快更轻量,推荐使用  
**本项目将不再维护**

### 关于本项目

* 使用Groovy语言编写,使用[`groovy-android-gradle-plugin`](https://github.com/groovy/groovy-android-gradle-plugin)构建
* 项目中全面使用svg矢量图,感谢[`BetterVectorDrawable`](https://github.com/a-student/BetterVectorDrawable)
* 对应GitHub地址:<https://github.com/zzhoujay/Gank4Android>

### release版本

由于github的release中上传比较慢可以到[此处下载](http://www.pgyer.com/gank4android)

### 截图
![运行截图](http://git.oschina.net/uploads/images/2015/0929/220758_085c1eb1_141009.jpeg "运行截图")
![运行截图](http://git.oschina.net/uploads/images/2015/0929/220831_147fc0c6_141009.jpeg "运行截图")
![运行截图](http://git.oschina.net/uploads/images/2015/0929/220846_6352f286_141009.jpeg "运行截图")
![运行截图](http://git.oschina.net/uploads/images/2015/0929/220909_17bb9a0e_141009.jpeg "运行截图")
![运行截图](http://git.oschina.net/uploads/images/2015/0929/220925_e86328e7_141009.jpeg "运行截图")
![运行截图](http://git.oschina.net/uploads/images/2015/0929/220933_ca9446c7_141009.jpeg "运行截图")
![运行截图](http://git.oschina.net/uploads/images/2015/0929/220940_187a5e9b_141009.jpeg "运行截图")
![运行截图](http://git.oschina.net/uploads/images/2015/0929/220953_e16a8999_141009.jpeg "运行截图")
![运行截图](http://git.oschina.net/uploads/images/2015/0929/220959_513cdc48_141009.jpeg "运行截图")
![运行截图](http://git.oschina.net/uploads/images/2015/0929/221006_39429de7_141009.jpeg "运行截图")

_by zzhoujay_


================================================
FILE: app/.gitignore
================================================
/build


================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'
    }
}
apply plugin: 'groovyx.grooid.groovy-android'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "zhou.gank.io"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 3
        versionName "1.11"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

project.androidGroovy {
    options {
        sourceCompatibility = '1.7'
        targetCompatibility = '1.7'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'org.codehaus.groovy:groovy:2.4.3:grooid'
    compile('org.codehaus.groovy:groovy-json:2.4.3') {
        transitive = false
    }
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.bettervectordrawable:lib:0.4'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.github.flavienlaurent.datetimepicker:library:0.0.2'
    compile 'zhou.widget:advanceadapter:1.0'

}


================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/zhou/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}


================================================
FILE: app/src/androidTest/java/zhou/gank/io/ApplicationTest.java
================================================
package zhou.gank.io;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
public class ApplicationTest extends ApplicationTestCase<Application> {
    public ApplicationTest() {
        super(Application.class);
    }
}

================================================
FILE: app/src/main/AndroidManifest.xml
================================================
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="zhou.gank.io">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.activity.HomeActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".ui.activity.TabActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.Tab" />
        <activity
            android:name=".ui.activity.WebActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".ui.activity.SettingActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".ui.activity.DailyActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".ui.activity.ImageGalleryActivity"
            android:screenOrientation="portrait" />
        <activity android:name=".ui.activity.CollectActivity" />
    </application>

</manifest>


================================================
FILE: app/src/main/groovy/zhou/gank/io/App.groovy
================================================
package zhou.gank.io

import android.app.Activity
import android.app.Application
import android.content.ClipData
import android.content.ClipboardManager
import android.net.Uri
import android.os.Environment
import android.os.Handler
import android.os.Looper
import android.support.v7.app.AppCompatActivity
import android.widget.Toast
import com.bettervectordrawable.VectorDrawableCompat
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import groovy.transform.CompileStatic
import zhou.gank.io.comment.Config
import zhou.gank.io.database.DatabaseManager
import zhou.gank.io.net.NetworkManager
import zhou.gank.io.util.Notifier

@CompileStatic
class App extends Application {

    public static final String SITE_URL = "http://gank.avosapps.com";
    public static final String TYPE_URL = SITE_URL + "/api/data";
    public static final String TIME_URL = SITE_URL + "/api/day";
    public static final String RANDOM_URL = SITE_URL + "/api/random/data";

    public static
    final File SAVE_PATH = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "gank")

    static {
        if (!SAVE_PATH.exists()) {
            SAVE_PATH.mkdir()
        }
    }

    private static App app;

    static App getInstance() {
        return app;
    }

    Gson gson;
    Handler mainHandler
    int cardLight, cardDark, textLight, textDark
    ArrayList<Notifier> notifiers
    public static boolean hasStarted

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;

        DatabaseManager.init(this)

        cardDark = getColor(R.color.cardview_dark_background)
        cardLight = getColor(R.color.cardview_light_background)
        textDark = getColor(R.color.material_grey_50)
        textLight = getColor(R.color.material_grey_1000)

        mainHandler = new Handler(Looper.getMainLooper())

        gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").create();
        NetworkManager.getInstance().init(this, gson)
        NetworkManager.getInstance().setDefaultHandle { e ->
            switch (e) {
                case SocketTimeoutException:
                    return Config.Error.TIME_OUT
                default:
                    return Config.Error.UNKOWN
            }
        }
        VectorDrawableCompat.enableResourceInterceptionFor(getResources(),
                R.drawable.ic_favorite_white_48px,
                R.drawable.ic_info_48px,R.drawable.ic_refresh_48px,
                R.drawable.ic_dashboard_48px, R.drawable.ic_event_48px,
                R.drawable.ic_extension_48px, R.drawable.ic_settings_black_48px,
                R.drawable.ic_menu_white_48px, R.drawable.ic_view_module_48px,
                R.drawable.ic_cloud_queue_48px, R.drawable.ic_cloud_off_48px,
                R.drawable.ic_insert_emoticon_48px, R.drawable.ic_bookmark_48px)

        Config.Configurable.HANDLE_BY_ME = true

        notifiers = new ArrayList<>()
    }

    static void toast(int id) {
        Toast.makeText(app, id, Toast.LENGTH_SHORT).show();
    }

    static void toast(String msg) {
        Toast.makeText(app, msg, Toast.LENGTH_SHORT).show();
    }

    static String getStr(int res) {
        return app.getResources().getString(res);
    }

    static int getColor(int res) {
        return app.getResources().getColor(res)
    }

    static File cacheFile() {
        return app.getCacheDir();
    }

    static void copy(String text) {
        ClipboardManager myClipboard;
        myClipboard = (ClipboardManager) app.getSystemService(CLIPBOARD_SERVICE);
        ClipData myClip;
        myClip = ClipData.newPlainText("text", text);
        myClipboard.setPrimaryClip(myClip);
    }

    static void copyUri(Uri uri) {
        ClipboardManager myClipboard;
        myClipboard = (ClipboardManager) app.getSystemService(CLIPBOARD_SERVICE);
        ClipData myClip;
        myClip = ClipData.newUri(app.getContentResolver(), "URI", uri);
        myClipboard.setPrimaryClip(myClip);
    }

    static void setTheme(Activity activity) {
        String theme = Config.getString(getStr(R.string.key_theme), "light")
        switch (theme) {
            case "light":
                activity.setTheme(R.style.AppTheme)
                break
            case "dark":
                activity.setTheme(R.style.AppThemeDark)
                break
        }
    }

    static boolean themeIsLight() {
        String theme = Config.getString(getStr(R.string.key_theme), "light")
        return theme == "light"
    }

    static boolean addNotifier(Notifier notifier) {
        app.notifiers.add(notifier)
    }

    static boolean removeNotifier(Notifier notifier) {
        app.notifiers.remove(notifier)
    }

    static void themeChanged() {
        app.notifiers.each {
            def notifier = it as Notifier
            notifier.notice(Config.Action.RESTART)
        }
    }

    static void setPrimaryColor(AppCompatActivity activity) {
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/MainActivity.groovy
================================================
package zhou.gank.io

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ObjectAnimator
import android.animation.PropertyValuesHolder
import android.content.Intent
import android.os.Bundle
import android.support.annotation.Nullable
import android.support.design.widget.FloatingActionButton
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.TextView
import groovy.transform.CompileStatic
import zhou.gank.io.database.DatabaseManager
import zhou.gank.io.model.Bookmark
import zhou.gank.io.ui.activity.HomeActivity

@CompileStatic
class MainActivity extends AppCompatActivity {

    FloatingActionButton fab
    TextView textView
    View background

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        App.setTheme(this)
        super.onCreate(savedInstanceState)
        if (App.hasStarted) {
            Open()
            return
        } else {
            App.hasStarted = true
        }
        setContentView(R.layout.activity_main);

        fab = findViewById(R.id.fab) as FloatingActionButton
        textView = findViewById(R.id.textView) as TextView
        background = findViewById(R.id.background)
        fab.postDelayed(this.&start, 200)
    }


    def void start() {
        View parent = fab.getParent() as View
        float scale = Math.sqrt(parent.getHeight() * parent.getHeight() + parent.getWidth() * parent.getWidth()) / fab.getHeight() as float
        PropertyValuesHolder holderX = PropertyValuesHolder.ofFloat("scaleX", scale)
        PropertyValuesHolder holderY = PropertyValuesHolder.ofFloat("scaleY", scale)
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(fab as Object, holderX, holderY).setDuration(500)
        animator.setInterpolator(new AccelerateDecelerateInterpolator())
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation)
                background.setBackgroundColor(MainActivity.this.getResources().getColor(R.color.material_purple_500) as int)
                fab.setVisibility(View.GONE)
                textView.setVisibility(View.VISIBLE)
            }
        })
        parent.getAlpha()


        PropertyValuesHolder holderA = PropertyValuesHolder.ofFloat("alpha", 0, 1)
        PropertyValuesHolder holderYm = PropertyValuesHolder.ofFloat("translationY", 0, 300)
        ObjectAnimator a = ObjectAnimator.ofPropertyValuesHolder(textView as Object, holderA, holderYm).setDuration(700)
        a.setInterpolator(new AccelerateDecelerateInterpolator())
        a.setStartDelay(500)

        a.addListener(new AnimatorListenerAdapter() {
            @Override
            void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation)
                Open()
            }
        })

        animator.start()
        a.start()
    }

    public void Open(View view = null) {
        startActivity(new Intent(this, HomeActivity.class));
        finish()
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/comment/Config.groovy
================================================
package zhou.gank.io.comment

import android.content.SharedPreferences
import android.preference.PreferenceManager
import groovy.transform.CompileStatic
import zhou.gank.io.App;

@CompileStatic
class Config {

    public static class Configurable {

        public static int DEFAULT_SIZE = 10

        public static boolean HANDLE_BY_ME = true

        public static int MAX_iteration = 7
    }

    public static class Static {

        public static final String TYPE = "type"

        public static final String URL = "url"

        public static final String TITLE = "title"

        public static final String CONTENT = "content"

        public static final String IS_RANDOM = "is_random"

        public static final String IS_IMAGE = "is_image"

        public static final String IS_MAIN = "is_main"

        public static final String IS_BOOKMARK = "is_bookmark"

        public static final String YEAR = "year"

        public static final String MONTH = "month"

        public static final String DAY = "day"

        public static final String URLS = "urls"

        public static final String POSITION = "position"
    }

    public static class Type {

        public static final String ANDROID = "Android"

        public static final String IOS = "iOS"

        public static final String RECOMMEND = "瞎推荐"

        public static final String RESOURCES = "拓展资源"

        public static final String WELFARE = "福利"

        public static final String VIDEO = "休息视频"

    }

    public static class Error {

        public static final String UNKOWN = "未知错误"

        public static final String TIME_OUT = "网络连接超时"

        public static final String FORMDATA_ = "数据格式出错"
    }

    public static class Action {

        //打开drawerLayout
        public static final int OPEN_DRAWER_LAYOUT = 0x111111

        public static final int CHANGE_DATE = 0x222222

        public static final int FINISH = 0x333333

        public static final int RESTART = 0x444444
    }

    public static String getString(String key, String d) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(App.getInstance())
        preferences.getString(key, d)
    }

    public static boolean getBoolean(String key, boolean d) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(App.getInstance())
        preferences.getBoolean(key, d)
    }

    public static int getInt(String key, int d) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(App.getInstance())
        preferences.getInt(key, d)
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/data/CollectProvider.groovy
================================================
package zhou.gank.io.data

import android.support.annotation.Nullable;
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.database.DatabaseManager
import zhou.gank.io.model.Gank

@CompileStatic
public class CollectProvider implements DataProvider<List<Gank>> {

    private List<Gank> ganks

    @Override
    void persistence() {

    }

    @Override
    List<Gank> get() {
        return ganks
    }

    @Override
    void set(@Nullable List<Gank> ganks, boolean more) {
        this.ganks = ganks
    }

    @Override
    void loadByCache(Closure closure) {
        new Thread({
            List<Gank> gs = DatabaseManager.getInstance().selectToGank()
            App.getInstance().getMainHandler().post({
                closure?.call(gs)
            })
        }).start()
    }

    @Override
    void load(Closure closure, boolean more) {

    }

    @Override
    boolean hasLoad() {
        return ganks != null
    }

    @Override
    boolean needCache() {
        return false
    }

    @Override
    boolean clearCache() {
        return false
    }

    @Override
    String key() {
        return "bookmark"
    }

    @Override
    void setNoticeable(boolean noticeable) {

    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/data/DataManager.groovy
================================================
package zhou.gank.io.data

import android.util.Log
import groovy.transform.CompileStatic

@CompileStatic
class DataManager {

    private static DataManager dataManager

    public static DataManager getInstance() {
        if (dataManager == null) {
            dataManager = new DataManager()
        }
        dataManager
    }

    private HashMap<String, DataProvider> providers

    private DataManager() {
        providers = new HashMap<>()
    }

    /**
     * 添加数据提供器(不进行重复检查)
     *
     * @param provider 提供器
     */
    public void add(DataProvider provider) {
        if (provider != null)
            providers.put(provider.key(), provider)
    }

    /**
     * 添加数据提供器
     *
     * @param provider 数据提供器
     * @param check 是否进行重复检查
     */
    public void add(DataProvider provider, boolean check) {
        if (provider == null) {
            return
        }
        if (check) {
            if (!providers.containsKey(provider.key())) {
                providers.put(provider.key(), provider)
            }
        } else {
            providers.put(provider.key(), provider)
        }
    }

    /**
     * 移除数据提供器
     *
     * @param key key
     */
    public void remove(String key) {
        providers.remove(key)
    }

    /**
     * 移出数据提供器
     *
     * @param provider 数据提供器
     */
    public void remove(DataProvider provider) {
        if (provider != null) {
            providers.remove(provider.key())
        }
    }

    /**
     * 获取数据 按照(内存->本地缓存->网络)的顺序获取
     *
     * @param key key
     * @param loadCallback 回调
     * @param < T >             type
     */
    public <T> void get(String key, Closure loadCallback) {
        try {
            def provider = providers.get(key) as DataProvider<T>
            get(provider, loadCallback)
        } catch (Exception e) {
            Log.d("get", "DataManager", e)
            loadCallback?.call()
        }
    }

    /**
     * 获取数据
     *
     * @param provider 数据提供器
     * @param loadCallback 回调
     * @param < T >             type
     */
    public <T> void get(DataProvider<T> provider, Closure loadCallback) {
        if (provider.hasLoad()) {
            loadCallback?.call(provider.get())
        } else {
            provider.loadByCache({t ->
                if (t != null) {
                    provider.set(t as T, false)
                    if (provider.needCache()) {
                        provider.persistence()
                    }
                    loadCallback?.call(provider.get())
                } else {
                    provider.load({tn ->
                        provider.set(tn as T, false);
                        if (provider.needCache()) {
                            provider.persistence()
                        }
                        loadCallback?.call(provider.get())
                    }, false)
                }
            });
        }
    }

    /**
     * 加载数据
     *
     * @param key key
     * @param loadCallback 回调
     * @param < T >             type
     */
    @SuppressWarnings("unchecked")
    public <T> void load(String key, Closure loadCallback, boolean more) {
        try {
            DataProvider<T> provider = (DataProvider<T>) providers.get(key)
            load(provider, loadCallback, more)
        } catch (Exception e) {
            Log.d("load", "DataManager", e)
            loadCallback?.call(null)
        }
    }

    /**
     * 加载数据
     *
     * @param provider 数据提供器
     * @param loadCallback 回调
     * @param < T >             type
     */
    public <T> void load(DataProvider<T> provider, Closure loadCallback, boolean more) {
        provider.load({t ->
            provider.set(t as T, more)
            if (provider.needCache()) {
                provider.persistence()
            }
            loadCallback?.call(provider.get())
        }, more);
    }

    public <T> void update(DataProvider<T> provider, Closure loadCallback) {
        load(provider, loadCallback, false)
    }

    void update(String key, Closure loadCallback) {
        load(key, loadCallback, false)
    }

    public <T> void more(DataProvider<T> provider, Closure loadCallback) {
        load(provider, loadCallback, true)
    }

    void more(String key, Closure loadCallback) {
        load(key, loadCallback, true)
    }

    /**
     * 持久化所有数据
     */
    void persistence() {
        for (Map.Entry<String, DataProvider> entry : providers.entrySet()) {
            DataProvider dataProvider = entry.getValue();
            if (dataProvider.needCache()) {
                dataProvider.persistence()
            }
        }
    }

    void clearAllCache() {
        for (Map.Entry<String, DataProvider> entry : providers.entrySet()) {
            DataProvider provider = entry.getValue()
            provider.clearCache()
        }
    }

    void clearCache(String key) {
        DataProvider provider = providers.get(key)
        if (provider != null) {
            provider.clearCache()
        }
    }

    boolean hasLoad(String key) {
        DataProvider provider = providers.get(key)
        provider != null && provider.hasLoad()
    }

    boolean exist(String key) {
        providers.containsKey(key)
    }

    public void reset() {
        providers.clear()
    }

}

================================================
FILE: app/src/main/groovy/zhou/gank/io/data/DataProvider.groovy
================================================
package zhou.gank.io.data

import android.support.annotation.NonNull
import android.support.annotation.Nullable
import groovy.transform.CompileStatic;

@CompileStatic
interface DataProvider<T> {

    /**
     * 数据持久化(应异步进行)
     */
    void persistence();

    /**
     * 获取数据
     *
     * @return 数据
     */
    @Nullable
    T get();

    /**
     * 设置数据
     *
     * @param t 数据
     */
    void set(@Nullable T t, boolean more);

    /**
     * 从缓存中加载数据(应异步实现)
     *
     * @param loadCallback 回调
     */
    void loadByCache(Closure closure);

    /**
     * 加载数据(必须异步实现)
     *
     * @param loadCallback 回调
     */
    void load(Closure closure, boolean more);

    /**
     * 是否已经加载
     *
     * @return boolean
     */
    boolean hasLoad();

    /**
     * 是否需要缓存
     *
     * @return boolean
     */
    boolean needCache();

    /**
     * 清空缓存
     */
    boolean clearCache();

    /**
     * 获取该加载器的唯一标识
     *
     * @return key
     */
    @NonNull
    String key();

    /**
     * 设置provide能否发出提醒
     * @param noticeable
     */
    void setNoticeable(boolean noticeable)

}

================================================
FILE: app/src/main/groovy/zhou/gank/io/data/RandomProvider.groovy
================================================
package zhou.gank.io.data

import android.support.annotation.NonNull
import android.support.annotation.Nullable
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.model.Gank
import zhou.gank.io.model.Result
import zhou.gank.io.net.NetworkManager
import zhou.gank.io.util.FileKit
import zhou.gank.io.util.HashKit
import zhou.gank.io.util.LogKit
import zhou.gank.io.util.NetworkKit

@CompileStatic
class RandomProvider implements DataProvider<List<Gank>> {

    private List<Gank> ganks
    private int size
    private String key, type
    private File file
    private boolean noticeable

    RandomProvider(String type, int size) {
        this.type = type;
        this.size = size;
        key = HashKit.md5("$type-$size-random.cache");
        file = new File(App.cacheFile(), key);
    }

    @Override
    void persistence() {
        if (hasLoad()) {
            new Thread({
                try {
                    FileKit.writeObject(file, ganks)
                } catch (Exception e) {
                    LogKit.d("persistence", "random", e)
                }
            }).start();
        }
    }

    @Nullable
    @Override
    List<Gank> get() {
        return ganks;
    }

    @Override
    void set(@Nullable List<Gank> ganHuos, boolean more) {
        this.ganks = ganHuos;
    }

    @Override
    void loadByCache(Closure closure) {
        def gks = null
        if (file.exists()) {
            try {
                gks = FileKit.readObject(file)
            } catch (Exception e) {
                LogKit.d("loadByCache", "random", e)
            }
        }
        closure?.call(gks)
    }

    @Override
    void load(Closure closure, boolean more) {
        if (NetworkManager.getInstance().isNetworkConnected()) {
            NetworkKit.random(type, size, { result ->
                def gks = null
                if (result instanceof Result) {
                    def r = result as Result
                    if (r?.isSuccess()) {
                        gks = r.results
                    } else {
                        if (noticeable)
                            App.toast(R.string.failure_get)
                    }
                } else {
                    if (noticeable)
                        App.toast(result as String)
                }
                closure?.call(gks)
            })
        } else {
            closure?.call()
            if (noticeable)
                App.toast(R.string.error_network)
        }
    }

    @Override
    boolean hasLoad() {
        return ganks != null;
    }

    @Override
    boolean needCache() {
        return false;
    }

    @Override
    boolean clearCache() {
        return file.exists() && file.delete();
    }

    @NonNull
    @Override
    String key() {
        return key;
    }

    @Override
    void setNoticeable(boolean noticeable) {
        this.noticeable = noticeable;
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/data/TimeProvider.groovy
================================================
package zhou.gank.io.data

import android.support.annotation.NonNull
import android.support.annotation.Nullable
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.model.GankDaily
import zhou.gank.io.model.ResultDaily
import zhou.gank.io.net.NetworkManager
import zhou.gank.io.util.FileKit
import zhou.gank.io.util.HashKit
import zhou.gank.io.util.LogKit
import zhou.gank.io.util.NetworkKit

@CompileStatic
class TimeProvider implements DataProvider<GankDaily> {

    private GankDaily daily
    int year, month, day
    private String key
    private File file
    private boolean noticeable
    private boolean needCache

    TimeProvider(int year, int month, int day) {
        this.year = year
        this.month = month
        this.day = day
        key = HashKit.md5("year:$year,month:$month,day:$day-cache")
        file = new File(App.cacheFile(), key)

        Calendar now = Calendar.getInstance()
        int y = now.get(Calendar.YEAR)
        if (year < y) {
            needCache = true
        } else if (year == y) {
            int m = now.get(Calendar.MONTH) + 1
            if (month < m) {
                needCache = true
            } else if (month == m) {
                int d = now.get(Calendar.DAY_OF_MONTH)
                needCache = day <= d
            } else {
                needCache = false
            }
        } else {
            needCache = false
        }
    }

    @Override
    void persistence() {
        if (hasLoad()) {
            new Thread({
                try {
                    FileKit.writeObject(file, daily)
                } catch (Exception e) {
                    LogKit.d("persistence", "time", e)
                }
            }).start()
        }
    }

    @Nullable
    @Override
    GankDaily get() {
        return daily
    }

    @Override
    void set(@Nullable GankDaily ganHuos, boolean more) {
        this.daily = ganHuos
    }

    @Override
    void loadByCache(Closure closure) {
        def d = null
        if (file.exists()) {
            new Thread({
                try {
                    d = FileKit.readObject(file)
                } catch (Exception e) {
                    LogKit.d("loadByCache", "time", e)
                }
                App.getInstance().getMainHandler().post({
                    closure?.call(d)
                })
            }).start()
        } else {
            closure?.call(d)
        }
    }

    @Override
    void load(Closure closure, boolean more) {
        if (NetworkManager.getInstance().isNetworkConnected()) {
            NetworkKit.time(year, month, day, { result ->
                def d = null
                if (result instanceof ResultDaily) {
                    def r = result as ResultDaily
                    if (r.isSuccess()) {
                        d = r.results
                    } else {
                        if (noticeable)
                            App.toast(R.string.failure_get)
                    }
                }
                closure?.call(d)
            })
        } else {
            closure?.call()
            if (noticeable)
                App.toast(R.string.error_network)
        }
    }

    @Override
    public boolean hasLoad() {
        return daily != null
    }

    @Override
    public boolean needCache() {
        return needCache
    }

    @Override
    public boolean clearCache() {
        return file.exists() && file.delete()
    }

    @NonNull
    @Override
    public String key() {
        return key
    }

    @Override
    void setNoticeable(boolean noticeable) {
        this.noticeable = noticeable
    }

    public TimeProvider getNextDay() {
        Calendar calendar = Calendar.getInstance()
        calendar.set(Calendar.YEAR, year)
        calendar.set(Calendar.MONTH, month - 1)
        calendar.set(Calendar.DAY_OF_MONTH, day)
        calendar.add(Calendar.DAY_OF_MONTH, 1)
        return new TimeProvider(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH))
    }

    public TimeProvider getPrevDay() {
        Calendar calendar = Calendar.getInstance()
        calendar.set(Calendar.YEAR, year)
        calendar.set(Calendar.MONTH, month - 1)
        calendar.set(Calendar.DAY_OF_MONTH, day)
        calendar.add(Calendar.DAY_OF_MONTH, -1)
        return new TimeProvider(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH))
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/data/TypeProvider.groovy
================================================
package zhou.gank.io.data

import android.support.annotation.NonNull
import android.support.annotation.Nullable
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.model.Gank
import zhou.gank.io.model.Result
import zhou.gank.io.net.NetworkManager
import zhou.gank.io.util.*

@CompileStatic
class TypeProvider implements DataProvider<List<Gank>> {

    private List<Gank> ganks
    private File file
    private String type, key
    private Pageable pageable
    private boolean noticeable

    TypeProvider(String type, int size) {
        this.type = type;
        key = HashKit.md5("${type}${size}-cache")
        file = new File(App.cacheFile(), key)
        pageable = new Pageable(1, size)
    }

    @Override
    void persistence() {
        if (hasLoad()) {
            new Thread({
                try {
                    FileKit.writeObject(file, new TypeGankEntity(pageable, ganks))
                } catch (Exception e) {
                    LogKit.d("persistence", "type", e)
                }
            }).start()
        }
    }

    @Nullable
    @Override
    List<Gank> get() {
        return ganks
    }

    @Override
    void set(@Nullable List<Gank> ganHuos, boolean more) {
        if (more && ganHuos != null && hasLoad()) {
            this.ganks.addAll(ganHuos)
        } else {
            this.ganks = ganHuos
        }
    }

    @Override
    void loadByCache(Closure closure) {
        def gks = null
        if (file.exists()) {
            new Thread({
                try {
                    def tge = FileKit.readObject(file) as TypeGankEntity
                    gks = tge.g
                    pageable = tge.p
                } catch (Exception e) {
                    LogKit.d("loadByCache", "type", e)
                }
            }).start()
            App.getInstance().getMainHandler().post({
                closure?.call(gks)
            })
        }else {
            closure?.call(gks)
        }
    }

    @Override
    void load(Closure closure, boolean more) {
        if (NetworkManager.getInstance().isNetworkConnected()) {
            if (more) {
                pageable.next()
            }
            NetworkKit.type(type, pageable.pageSize, pageable.pageNo, { result ->
                def gks = null
                if (result instanceof Result) {
                    def r = result as Result
                    if (r?.isSuccess()) {
                        gks = r.results
                    } else {
                        if (more) {
                            pageable.prev()
                        }
                        if (noticeable)
                            App.toast(R.string.failure_get)
                    }
                } else {
                    if (noticeable)
                        App.toast(result as String)
                }
                closure?.call(gks)
            })
        } else {
            if (noticeable)
                App.toast(R.string.error_network)
            closure?.call()
        }
    }

    @Override
    boolean hasLoad() {
        return ganks != null
    }

    @Override
    boolean needCache() {
        return true
    }

    @Override
    boolean clearCache() {
        return file.exists() && file.delete()
    }

    @NonNull
    @Override
    String key() {
        return key
    }

    @Override
    void setNoticeable(boolean noticeable) {
        this.noticeable = noticeable
    }

    public static class TypeGankEntity implements Serializable {

        public Pageable p
        public List<Gank> g

        TypeGankEntity(Pageable p, List<Gank> g) {
            this.p = p
            this.g = g
        }

        TypeGankEntity() {
        }
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/database/DatabaseManager.groovy
================================================
package zhou.gank.io.database

import android.content.ContentValues
import android.content.Context
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper;
import groovy.transform.CompileStatic
import zhou.gank.io.model.Bookmark
import zhou.gank.io.model.Gank

@CompileStatic
public class DatabaseManager {

    public static final String TABLE_NAME = "bookmark"
    public static final String URL = "url"
    public static final String TITLE = "title"
    public static final String TIME = "time"

    private static DatabaseManager databaseManager

    public static DatabaseManager getInstance() {
        return databaseManager
    }

    public static void init(Context context) {
        databaseManager = new DatabaseManager(context)
    }


    private DatabaseHelper databasehelper
    private SQLiteDatabase database

    private DatabaseManager(Context context) {
        databasehelper = new DatabaseHelper(context)
    }

    public void insert(Bookmark bookmark) {
        start()
        ContentValues cv = new ContentValues(3)
        cv.put(URL, bookmark.url)
        cv.put(TITLE, bookmark.title)
        cv.put(TIME, bookmark.time.getTime())
        database.insert(TABLE_NAME, null, cv)
        end()
    }

    public void delete(String url) {
        start()
        database.delete(TABLE_NAME, "url=?", url)
        end()
    }

    public List<Bookmark> select() {
        start()
        String sql = "select * from $TABLE_NAME order by $TIME desc;"
        Cursor cursor = database.rawQuery(sql)
        int count = cursor?.getCount()
        List<Bookmark> bookmarks = new ArrayList<>(count)
        if (cursor) {
            cursor.moveToFirst()
            for (int i = 0; i < count; i++) {
                String url = cursor.getString(0)
                String title = cursor.getString(1)
                long time = cursor.getLong(2)
                bookmarks.add(new Bookmark(url, title, new Date(time)))
                cursor.moveToNext()
            }
        }
        end()
        return bookmarks
    }

    public List<Gank> selectToGank() {
        start()
        String sql = "select * from $TABLE_NAME order by $TIME desc;"
        Cursor cursor = database.rawQuery(sql)
        int count = cursor?.getCount()
        List<Gank> gs = new ArrayList<>(count)
        if (cursor) {
            cursor.moveToFirst()
            for (int i = 0; i < count; i++) {
                String url = cursor.getString(0)
                String title = cursor.getString(1)
                long time = cursor.getLong(2)
                gs.add(new Gank(title, url, new Date(time)))
                cursor.moveToNext()
            }
        }
        end()
        return gs
    }

    public boolean isExist(String url) {
        start()
        String sql = "select * from $TABLE_NAME where $URL=?"
        Cursor cursor = database.rawQuery(sql, url)
        boolean flag = false
        if (cursor && cursor.getCount() > 0) {
            flag = true
        }
        end()
        return flag
    }


    private void start() {
        database = databasehelper.getWritableDatabase()
    }

    private end() {
        database?.close()
    }

    private class DatabaseHelper extends SQLiteOpenHelper {

        private static final int VERSION = 1
        private static final String DATABASE_NAME = "ganke"

        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, VERSION)
        }

        @Override
        void onCreate(SQLiteDatabase sqLiteDatabase) {
            String sql = "create table $TABLE_NAME (${DatabaseManager.URL} text primary key,${TITLE} text not null,$TIME long not null);"
            println(sql)
            sqLiteDatabase.execSQL(sql)
        }

        @Override
        void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

        }
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/model/BaseResult.groovy
================================================
package zhou.gank.io.model

import groovy.transform.CompileStatic;

@CompileStatic
abstract class BaseResult implements Serializable {

    boolean error

    abstract boolean isSuccess()

}

================================================
FILE: app/src/main/groovy/zhou/gank/io/model/Bookmark.groovy
================================================
package zhou.gank.io.model;

import groovy.transform.CompileStatic

@CompileStatic
public class Bookmark implements Serializable {

    public String url
    public String title
    public Date time

    Bookmark(String url, String title, Date time) {
        this.url = url
        this.title = title
        this.time = time
    }

    Bookmark(String url, String title) {
        this.url = url
        this.title = title
        this.time = new Date()
    }

    Bookmark() {
    }


    @Override
    public String toString() {
        return "Bookmark{" +
                "url='" + url + '\'' +
                ", title='" + title + '\'' +
                ", time=" + time +
                '}';
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/model/Gank.groovy
================================================
package zhou.gank.io.model

import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString;

@ToString
@EqualsAndHashCode
@CompileStatic
class Gank implements Serializable{

    public String who
    public String desc
    public String type
    public String url
    public String objectId
    public boolean used
    public Date publishedAt
    public Date createdAt
    public Date updatedAt

    Gank(String who, String desc, String type, String url, String objectId, boolean used, Date publishedAt, Date createdAt, Date updatedAt) {
        this.who = who
        this.desc = desc
        this.type = type
        this.url = url
        this.objectId = objectId
        this.used = used
        this.publishedAt = publishedAt
        this.createdAt = createdAt
        this.updatedAt = updatedAt
    }

    Gank(String desc, String url, Date createdAt) {
        this.desc = desc
        this.url = url
        this.createdAt = createdAt
    }

    Gank() {
    }


    @Override
    public String toString() {
        return "Gank{" +
                "who='" + who + '\'' +
                ", desc='" + desc + '\'' +
                ", type='" + type + '\'' +
                ", url='" + url + '\'' +
                ", objectId='" + objectId + '\'' +
                ", used=" + used +
                ", publishedAt=" + publishedAt +
                ", createdAt=" + createdAt +
                ", updatedAt=" + updatedAt +
                '}';
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/model/GankDaily.groovy
================================================
package zhou.gank.io.model

import groovy.transform.CompileStatic
import groovy.transform.ToString;

@CompileStatic
@ToString(includeNames = true)
class GankDaily implements Serializable {

    public List<String> types;
    public List<List<Gank>> ganks;

    int size() {
        return types.size();
    }

    boolean isEmpty() {
        return types == null ? true : types.isEmpty() || ganks == null ? true : ganks.isEmpty()
    }

    String getType(int index) {
        return types.get(index);
    }

    List<Gank> getGanhuo(int index) {
        return ganks.get(index);
    }

    GankDaily(List<String> types, List<List<Gank>> ganks) {
        this.types = types
        this.ganks = ganks
    }

    GankDaily() {
    }


    @Override
    public String toString() {
        return "GankDaily{" +
                "types=" + types +
                ", ganks=" + ganks +
                '}';
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/model/Result.groovy
================================================
package zhou.gank.io.model

import groovy.transform.CompileStatic;

@CompileStatic
class Result extends BaseResult {

    public List<Gank> results

    Result(boolean error, List<Gank> results) {
        this.error = error
        this.results = results
    }

    Result() {
    }


    @Override
    public String toString() {
        return "Result{" +
                "error=" + error +
                ", results=" + results +
                '}';
    }

    @Override
    boolean isSuccess() {
        !error
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/model/ResultDaily.groovy
================================================
package zhou.gank.io.model

import groovy.transform.CompileStatic
import groovy.transform.ToString;

@CompileStatic
@ToString
class ResultDaily extends BaseResult {

    public GankDaily results;

    ResultDaily(boolean error, GankDaily results) {
        this.error = error
        this.results = results
    }

    ResultDaily() {
    }

    @Override
    public String toString() {
        return "ResultDaily{" +
                "error=" + error +
                ", results=" + results +
                '}';
    }

    @Override
    boolean isSuccess() {
        !error
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/net/NetworkManager.groovy
================================================
package zhou.gank.io.net

import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkInfo
import android.os.Handler
import android.os.Looper
import android.util.Log
import com.google.gson.Gson
import com.squareup.okhttp.Callback
import com.squareup.okhttp.OkHttpClient
import com.squareup.okhttp.Request
import com.squareup.okhttp.Response
import groovy.transform.CompileStatic
import zhou.gank.io.model.Result
import zhou.gank.io.util.LogKit

import java.lang.reflect.Type
import java.util.concurrent.TimeUnit

//@CompileStatic
class NetworkManager {

    OkHttpClient client
    Gson gson
    Handler handler
    Closure defaultHandle
    Context context

    private static NetworkManager networkManager;

    static NetworkManager getInstance() {
        return networkManager
    }

    static void init(Context context, Gson gson) {
        networkManager = new NetworkManager(context, gson)
    }

    private NetworkManager(Context context, Gson gson) {
        client = new OkHttpClient()
        client.setConnectTimeout(5, TimeUnit.SECONDS)
        client.setReadTimeout(5, TimeUnit.SECONDS)
        client.setWriteTimeout(5, TimeUnit.SECONDS)
        this.gson = gson;
        this.context = context
        handler = new Handler(Looper.getMainLooper())
    }

    void requestString(Request r, Closure closure) {
        client.newCall(r).enqueue(new Callback() {
            @Override
            void onFailure(Request request, IOException e) {
                handler.post({
                    closure(e)
                })
            }

            @Override
            void onResponse(Response response) throws IOException {
                String body = response.body().string();
                LogKit.d("requestString", body)
                handler.post({
                    closure(body)
                })
            }
        })
    }

    public <T> void request(Request r, Closure closure, Class<T> aClass) {
        client.newCall(r).enqueue(new Callback() {
            @Override
            void onFailure(Request request, IOException e) {
                handler.post({
                    closure(defaultHandle?.call(e))
                })
            }

            @Override
            void onResponse(Response response) throws IOException {
                String body = response.body().string()
                Log.d("success", body)
                def result = gson.fromJson(body, aClass);
                handler.post({
                    closure(result)
                })
            }
        })
        Log.d("request", r.urlString())
    }

    public <T> void request(Request r, Closure closure, Type type) {
        client.newCall(r).enqueue(new Callback() {
            @Override
            void onFailure(Request request, IOException e) {
                handler.post({
                    closure(defaultHandle?.call(e))
                })
            }

            @Override
            void onResponse(Response response) throws IOException {
                String body = response.body().string()
                Log.d("success", body)
                def result = gson.fromJson(body, type)
                handler.post({
                    closure(result)
                })
            }
        })
    }

    boolean isNetworkConnected() {
        ConnectivityManager connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo()
        networkInfo != null && networkInfo.isAvailable()
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/activity/CollectActivity.groovy
================================================
package zhou.gank.io.ui.activity

import android.os.Bundle
import android.support.annotation.Nullable;
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.ui.fragment.GankFragment

@CompileStatic
public class CollectActivity extends ToolbarActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (App.themeIsLight()) {
            setTheme(R.style.AppTheme_Tab)
        } else {
            setTheme(R.style.AppTheme_TabDark)
        }
        super.onCreate(savedInstanceState)
        quickFinish()
        setTitle(R.string.nav_collect)

        add(GankFragment.newInstance(null, true, false, true))
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/activity/DailyActivity.groovy
================================================
package zhou.gank.io.ui.activity

import android.content.Intent
import android.os.Bundle
import android.support.annotation.Nullable
import android.support.design.widget.CoordinatorLayout
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import com.fourmob.datetimepicker.date.DatePickerDialog
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.comment.Config
import zhou.gank.io.ui.fragment.DailyFragment
import zhou.gank.io.util.Notifier
import zhou.gank.io.util.TimeKit

@CompileStatic
public class DailyActivity extends AppCompatActivity implements Notifier {

    CoordinatorLayout coordinatorLayout;
    Fragment currFragment
    int year, month, day

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        App.setTheme(this)
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_compat)

        def i = getIntent()
        def times = TimeKit.getTime()
        year = i.getIntExtra(Config.Static.YEAR, times[0])
        month = i.getIntExtra(Config.Static.MONTH, times[1])
        day = i.getIntExtra(Config.Static.DAY, times[2])

        add(DailyFragment.newInstance(year, month, day))
    }

    def add(Fragment f) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, f).commit();
        this.currFragment = f;
    }

    def replace(Fragment f) {
        if (currFragment == f) {
            return
        }
        coordinatorLayout.removeAllViews()
        getSupportFragmentManager().beginTransaction().remove(currFragment).add(R.id.container, f).commit()
        this.currFragment = f
    }

    @Override
    void notice(int noticeId) {
        switch (noticeId) {
            case Config.Action.FINISH:
                finish()
                break
            case Config.Action.CHANGE_DATE:
                DatePickerDialog dialog = DatePickerDialog.newInstance({ datePickerDialog, year, month, day ->
                    Intent i = new Intent(this, DailyActivity.class)
                    i.putExtra(Config.Static.YEAR, year as int)
                    i.putExtra(Config.Static.MONTH, (month as int) + 1)
                    i.putExtra(Config.Static.DAY, day as int)
                    startActivity(i)
                }, year, month - 1, day)
                dialog.setVibrate(false)
                dialog.show(getSupportFragmentManager(), "time")
//                DatePickerDialog dialog = new DatePickerDialog(this, { picker, year, month, day ->
//                    Intent i = new Intent(this, DailyActivity.class)
//                    i.putExtra(Config.Static.YEAR, year as int)
//                    i.putExtra(Config.Static.MONTH, (month as int) + 1)
//                    i.putExtra(Config.Static.DAY, day as int)
//                    startActivity(i)
//                }, year, month - 1, day)
//                dialog.show()
//                DatePickerDialog dialog = DatePickerDialog.newInstance(this, times[0], times[1] - 1, times[2])
//                dialog.vibrate(false)
//                dialog.show(getFragmentManager(), "date")
                break
        }
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/activity/HomeActivity.groovy
================================================
package zhou.gank.io.ui.activity

import android.content.Intent
import android.os.Bundle
import android.support.design.widget.CoordinatorLayout
import android.support.design.widget.NavigationView
import android.support.v4.app.Fragment
import android.support.v4.view.GravityCompat
import android.support.v4.widget.DrawerLayout
import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import com.fourmob.datetimepicker.date.DatePickerDialog
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.comment.Config
import zhou.gank.io.ui.dialog.InfoDialog
import zhou.gank.io.ui.fragment.DailyFragment
import zhou.gank.io.util.Notifier
import zhou.gank.io.util.TextKit
import zhou.gank.io.util.TimeKit

@CompileStatic
class HomeActivity extends AppCompatActivity implements Notifier {

    static int needRecreate

    DrawerLayout drawerLayout;
    NavigationView navigationView;
    CoordinatorLayout coordinatorLayout;

    private DailyFragment dailyFragment;
    private Fragment currFragment;
    private boolean isRecreate

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        App.setTheme(this)
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        initView();

        dailyFragment = DailyFragment.newInstance(-1, -1, -1, true)

        add(dailyFragment)

        App.addNotifier(this)
    }

    def initView() {
        drawerLayout = findViewById(R.id.drawer_layout) as DrawerLayout
        navigationView = findViewById(R.id.nav_view) as NavigationView
        coordinatorLayout = findViewById(R.id.container) as CoordinatorLayout

        navigationView.setNavigationItemSelectedListener({ item ->
            def i = item as MenuItem
            drawerLayout.closeDrawers()
            switch (i.getItemId()) {
                case R.id.nav_daily:
                    replace(dailyFragment)
                    return true
                case R.id.nav_type:
                    Intent intent = new Intent(this, TabActivity.class)
                    intent.putExtra(Config.Static.IS_RANDOM, false)
                    App.getInstance().getMainHandler().postDelayed({
                        startActivity(intent)
                    }, 250)
                    return true
                case R.id.nav_random:
                    Intent intent = new Intent(this, TabActivity.class)
                    intent.putExtra(Config.Static.IS_RANDOM, true)
                    App.getInstance().getMainHandler().postDelayed({
                        startActivity(intent)
                    }, 250)
                    return true
                case R.id.nav_collect:
                    Intent intent = new Intent(this, CollectActivity.class)
                    App.getInstance().getMainHandler().postDelayed({
                        startActivity(intent)
                    }, 250)
                    return true
                case R.id.nav_info:
                    def info = InfoDialog.newInstance(getString(R.string.nav_info), TextKit.getInfo())
                    info.show(getSupportFragmentManager(), "info")
                    return true
                case R.id.nav_setting:
                    def intent1 = new Intent(this, SettingActivity.class)
                    App.getInstance().getMainHandler().postDelayed({
                        startActivity(intent1)
                    }, 200)
                    return true
            }
            return false
        })

    }

    def add(Fragment f) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, f).commit();
        this.currFragment = f;
    }

    def replace(Fragment f) {
        if (currFragment == f) {
            return
        }
        coordinatorLayout.removeAllViews()
        getSupportFragmentManager().beginTransaction().remove(currFragment).add(R.id.container, f).commit()
        this.currFragment = f
    }

    def remove() {
        if (currFragment) {
            getSupportFragmentManager().beginTransaction().remove(currFragment).commit()
            coordinatorLayout.removeAllViews()
            this.currFragment = null
        }
    }

    @Override
    void notice(int noticeId) {
        switch (noticeId) {
            case Config.Action.OPEN_DRAWER_LAYOUT:
                drawerLayout.openDrawer(GravityCompat.START)
                break
            case Config.Action.CHANGE_DATE:
                def times = TimeKit.getTime()
                DatePickerDialog dialog = DatePickerDialog.newInstance({ picker, year, month, day ->
                    Intent i = new Intent(this, DailyActivity.class)
                    i.putExtra(Config.Static.YEAR, year as int)
                    i.putExtra(Config.Static.MONTH, (month as int) + 1)
                    i.putExtra(Config.Static.DAY, day as int)
                    startActivity(i)
                }, times[0], times[1] - 1, times[2])
                dialog.setVibrate(false)
                dialog.show(getSupportFragmentManager(), "date")
                break
            case Config.Action.RESTART:
                needRecreate = 1
                break
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy()
        App.removeNotifier(this)
    }

    @Override
    protected void onResume() {
        super.onResume()
        if (needRecreate == 1) {
            remove()
            recreate()
            needRecreate++
            return
        }
        if (needRecreate == 2) {
            App.getInstance().getMainHandler().postDelayed({
                dailyFragment.requestData()
            }, 200)
            needRecreate = 0
        }
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/activity/ImageGalleryActivity.groovy
================================================
package zhou.gank.io.ui.activity

import android.content.Intent
import android.os.Bundle
import android.support.annotation.Nullable
import groovy.transform.CompileStatic
import zhou.gank.io.comment.Config
import zhou.gank.io.ui.fragment.ImageGalleryFragment

@CompileStatic
public class ImageGalleryActivity extends ToolbarActivity {

    ArrayList<String> urls

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)
        quickFinish()

        Intent i = getIntent()
        urls = i.getStringArrayListExtra(Config.Static.URLS)
        add(ImageGalleryFragment.newInstance(urls, i.getIntExtra(Config.Static.POSITION, 0)))
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/activity/SettingActivity.groovy
================================================
package zhou.gank.io.ui.activity

import android.os.Bundle
import groovy.transform.CompileStatic
import zhou.gank.io.R
import zhou.gank.io.ui.fragment.SettingFragment

@CompileStatic
public class SettingActivity extends ToolbarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)
        quickFinish()
        setTitle(R.string.title_setting)

        getFragmentManager().beginTransaction().add(R.id.container, new SettingFragment()).commit()
    }


}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/activity/TabActivity.groovy
================================================
package zhou.gank.io.ui.activity

import android.content.Intent
import android.os.Bundle
import android.support.annotation.Nullable
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentPagerAdapter
import android.support.v4.view.PagerAdapter
import android.support.v4.view.ViewPager
import android.support.v7.app.ActionBar
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.MenuItem;
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.comment.Config
import zhou.gank.io.ui.fragment.GankFragment

@CompileStatic
public class TabActivity extends AppCompatActivity {

    boolean isRandom

    Toolbar toolbar
    TabLayout tabLayout
    ViewPager viewPager
    int[] ids = [R.string.nav_android, R.string.nav_ios, R.string.nav_recommend, R.string.nav_resource, R.string.nav_welfare, R.string.nav_video] as int[]
    Fragment[] fragments

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (App.themeIsLight()) {
            setTheme(R.style.AppTheme_Tab)
        } else {
            setTheme(R.style.AppTheme_TabDark)
        }
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tab)

        Intent intent = getIntent()
        isRandom = intent.getBooleanExtra(Config.Static.IS_RANDOM, false)

        fragments = new Fragment[6]

        fragments[0] = GankFragment.newInstance(Config.Type.ANDROID, isRandom)
        fragments[1] = GankFragment.newInstance(Config.Type.IOS, isRandom)
        fragments[2] = GankFragment.newInstance(Config.Type.RECOMMEND, isRandom)
        fragments[3] = GankFragment.newInstance(Config.Type.RESOURCES, isRandom)
        fragments[4] = GankFragment.newInstance(Config.Type.WELFARE, isRandom, true)
        fragments[5] = GankFragment.newInstance(Config.Type.VIDEO, isRandom)

        initView()
    }

    void initView() {
        toolbar = findViewById(R.id.toolbar) as Toolbar
        setSupportActionBar(toolbar)
        ActionBar actionBar = getSupportActionBar()
        actionBar?.setDisplayHomeAsUpEnabled(true)

        tabLayout = findViewById(R.id.tabs) as TabLayout
        viewPager = findViewById(R.id.viewpager) as ViewPager

        ids.each { tabLayout.addTab(tabLayout.newTab().setText(getString(it as Integer))) }

        PagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            Fragment getItem(int position) {
                fragments[position]
            }

            @Override
            int getCount() {
                return fragments.length
            }

            @Override
            CharSequence getPageTitle(int position) {
                return getString(ids[position])
            }
        }
        viewPager.setAdapter(adapter)
        tabLayout.setupWithViewPager(viewPager)
        tabLayout.setTabsFromPagerAdapter(adapter)

        if (isRandom) {
            setTitle(R.string.nav_random)
        } else {
            setTitle(R.string.nav_type)
        }
    }

    @Override
    boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish()
                return true
        }
        return super.onOptionsItemSelected(item)
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/activity/ToolbarActivity.groovy
================================================
package zhou.gank.io.ui.activity

import android.os.Bundle
import android.support.annotation.Nullable
import android.support.design.widget.CoordinatorLayout
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.KeyEvent
import android.view.MenuItem;
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.ui.fragment.BaseFragment

@CompileStatic
public class ToolbarActivity extends AppCompatActivity {

    Toolbar toolbar
    CoordinatorLayout coordinatorLayout
    BaseFragment currFragment
    boolean quick

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        App.setTheme(this)
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_toolbar)
        toolbar = findViewById(R.id.toolbar) as Toolbar
        coordinatorLayout = findViewById(R.id.container) as CoordinatorLayout

        setSupportActionBar(toolbar)
    }

    def quickFinish() {
        def actionBar = getSupportActionBar()
        actionBar?.setDisplayHomeAsUpEnabled(true)
        quick = true
    }

    def add(BaseFragment f) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, f).commit();
        currFragment = f
    }

    def replace(BaseFragment f) {
        coordinatorLayout.removeAllViews()
        getSupportFragmentManager().beginTransaction().remove(currFragment).add(R.id.container, f).commit()
        currFragment = f
    }

    @Override
    boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                if (quick) {
                    finish()
                    return true
                }
                break
        }
        return super.onOptionsItemSelected(item)
    }

    @Override
    boolean onKeyDown(int keyCode, KeyEvent event) {
        return currFragment?.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event)
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/activity/WebActivity.groovy
================================================
package zhou.gank.io.ui.activity

import android.os.Bundle
import android.support.annotation.Nullable
import groovy.transform.CompileStatic
import zhou.gank.io.R
import zhou.gank.io.comment.Config
import zhou.gank.io.ui.fragment.WebFragment

@CompileStatic
public class WebActivity extends ToolbarActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)
        quickFinish()
        def i = getIntent()

        String title
        title = i.getStringExtra(Config.Static.TITLE)
        if (title == null) {
            title = getString(R.string.app_name)
        }
        setTitle(title)

        add(WebFragment.newInstance(i.getStringExtra(Config.Static.URL), title))
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/adapter/BaseAdapter.groovy
================================================
package zhou.gank.io.ui.adapter

import android.support.v7.widget.RecyclerView
import groovy.transform.CompileStatic
import zhou.gank.io.model.Gank

@CompileStatic
public
abstract class BaseAdapter<T extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<T> {

    List<Gank> ganks
    Closure clickListener, longClickListener

    void setGanks(List<Gank> ganks) {
        this.ganks = ganks
        notifyDataSetChanged()
    }

    void setClickListener(Closure clickListener) {
        this.clickListener = clickListener
    }

    void setLongClickListener(Closure longClickListener) {
        this.longClickListener = longClickListener
    }

    void removeItem(int position) {

    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/adapter/DailyAdapter.groovy
================================================
package zhou.gank.io.ui.adapter

import android.support.v7.widget.CardView
import android.support.v7.widget.RecyclerView
import android.text.method.LinkMovementMethod
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.model.GankDaily
import zhou.gank.io.util.TextKit

@CompileStatic
class DailyAdapter extends BaseAdapter<Holder> {

    private GankDaily daily;

    @Override
    Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        Holder holder = new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_daily, null));
        return holder;
    }

    @Override
    void onBindViewHolder(Holder holder, int position) {
        holder.title.setText(daily.getType(position));
        holder.content.setText(TextKit.generate(daily.getGanhuo(position), App.getInstance().getResources().getColor(R.color.material_lightBlue_500)));
    }

    @Override
    int getItemCount() {
        return daily == null ? 0 : daily.size()
    }

    static class Holder extends RecyclerView.ViewHolder {

        public TextView title, content;

        public Holder(View itemView) {
            super(itemView);

            title = (TextView) itemView.findViewById(R.id.title);
            content = (TextView) itemView.findViewById(R.id.content);

            if (itemView instanceof CardView) {
                def card = itemView as CardView
                if (App.themeIsLight()) {
                    card.setCardBackgroundColor(App.getInstance().getCardLight())
                    title.setTextColor(App.getInstance().getTextLight())
                } else {
                    card.setCardBackgroundColor(App.getInstance().getCardDark())
                    title.setTextColor(App.getInstance().getTextDark())
                }
            }

            content.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }

    void setDaily(GankDaily daily) {
        this.daily = daily;
        notifyDataSetChanged();
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/adapter/GankAdapter.groovy
================================================
package zhou.gank.io.ui.adapter

import android.support.v7.widget.CardView
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.model.Gank
import zhou.gank.io.util.TimeKit

@CompileStatic
public class GankAdapter extends BaseAdapter<Holder> {

    List<Gank> ganks

    @Override
    Holder onCreateViewHolder(ViewGroup viewGroup, int i) {
        def holder = new Holder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_gank, null))
        holder.setListener { p ->
            Gank gank = ganks?.get(p as int)
            clickListener?.call(gank)
        }
        holder.setLongListener { v, p ->
            Gank gank = ganks?.get(p as int)
            longClickListener?.call(v, gank, p)
        }
        return holder
    }

    @Override
    void onBindViewHolder(Holder holder, int i) {
        Gank gank = ganks.get(i)

        holder.title.setText(gank.desc)
        holder.user.setText(gank.who)
        holder.time.setText(TimeKit.format(gank.createdAt))
    }

    @Override
    int getItemCount() {
        return ganks == null ? 0 : ganks.size()
    }

    static class Holder extends RecyclerView.ViewHolder {

        public TextView title, user, time

        Closure listener, longListener

        Holder(View itemView) {
            super(itemView)

            title = itemView.findViewById(R.id.title) as TextView
            user = itemView.findViewById(R.id.user) as TextView
            time = itemView.findViewById(R.id.time) as TextView

            if (itemView instanceof CardView) {
                def card = itemView as CardView
                if (App.themeIsLight()) {
                    card.setCardBackgroundColor(App.getInstance().getCardLight())
                } else {
                    card.setCardBackgroundColor(App.getInstance().getCardDark())
                }
            }

            itemView.setOnClickListener({ v ->
                listener?.call(getAdapterPosition())
            })

            itemView.setOnLongClickListener({ v ->
                longListener?.call(itemView, getAdapterPosition())
            })
        }

        void setListener(Closure listener) {
            this.listener = listener
        }
    }

    void setGanks(List<Gank> ganks) {
        this.ganks = ganks
        notifyDataSetChanged()
    }

    @Override
    void removeItem(int position) {
        ganks.remove(position)
        notifyItemRemoved(position)
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/adapter/ImageAdapter.groovy
================================================
package zhou.gank.io.ui.adapter

import android.support.v7.widget.CardView
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.squareup.picasso.Picasso
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.model.Gank
import zhou.gank.io.util.TimeKit

@CompileStatic
public class ImageAdapter extends BaseAdapter<Holder> {

    private List<Gank> ganks

    @Override
    Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        Holder holder = new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_image, null))
        holder.setListener { p ->
            Gank gank = ganks?.get(p as int)
            clickListener?.call(gank, p)
        }
        return holder
    }

    @Override
    void onBindViewHolder(Holder holder, int position) {
        Gank gank = ganks.get(position)

        Picasso.with(holder.icon.getContext()).load(gank.url).into(holder.icon)
        holder.who.setText(gank.who)
        holder.time.setText(TimeKit.format(gank.createdAt))
    }

    @Override
    int getItemCount() {
        return ganks == null ? 0 : ganks.size()
    }

    public static class Holder extends RecyclerView.ViewHolder {

        ImageView icon
        TextView who, time

        Closure listener

        Holder(View itemView) {
            super(itemView)

            icon = itemView.findViewById(R.id.icon) as ImageView
            who = itemView.findViewById(R.id.who) as TextView
            time = itemView.findViewById(R.id.time) as TextView

            if (itemView instanceof CardView) {
                def card = itemView as CardView
                if (App.themeIsLight()) {
                    card.setCardBackgroundColor(App.getInstance().getCardLight())
                } else {
                    card.setCardBackgroundColor(App.getInstance().getCardDark())
                }
            }

            itemView.setOnClickListener({ v ->
                listener?.call(getAdapterPosition())
            })
        }

        void setListener(Closure listener) {
            this.listener = listener
        }
    }

    void setGanks(List<Gank> ganks) {
        this.ganks = ganks
        notifyDataSetChanged()
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/adapter/ImageGalleryAdapter.groovy
================================================
package zhou.gank.io.ui.adapter

import android.content.Context
import android.support.v4.view.PagerAdapter
import android.support.v4.view.ViewPager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso;
import groovy.transform.CompileStatic
import zhou.gank.io.R

@CompileStatic
public class ImageGalleryAdapter extends PagerAdapter {

    List<String> urls

    ImageGalleryAdapter(List<String> urls) {
        this.urls = urls
    }

    @Override
    int getCount() {
        return urls == null ? 0 : urls.size()
    }

    @Override
    boolean isViewFromObject(View view, Object object) {
        return view.is(object)
    }

    @Override
    Object instantiateItem(ViewGroup container, int position) {
        Context context = container.getContext()
        View v = LayoutInflater.from(context).inflate(R.layout.layout_gallery, null)
        ImageView imageView = v.findViewById(R.id.image) as ImageView

        View error = v.findViewById(R.id.error_layout)
//        View progress = v.findViewById(R.id.progressBar)

        Closure loadImage = { view ->
//            progress.setVisibility(View.VISIBLE)
            error.setVisibility(View.GONE)
            Picasso.with(context).load(urls[position]).into(imageView, new Callback() {
                @Override
                void onSuccess() {
//                    progress.setVisibility(View.GONE)
                }

                @Override
                void onError() {
//                    progress.setVisibility(View.GONE)
                    error.setVisibility(View.VISIBLE)
                }
            })
        }

//        error.setOnClickListener(loadImage)

        loadImage(null)

        (container as ViewPager).addView(v, 0);
        return v
    }

    @Override
    void destroyItem(ViewGroup container, int position, Object object) {
        (container as ViewPager).removeView(object as View);
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/dialog/InfoDialog.groovy
================================================
package zhou.gank.io.ui.dialog

import android.app.Dialog
import android.os.Bundle
import android.support.annotation.Nullable
import android.support.v4.app.DialogFragment
import android.support.v7.app.AlertController
import android.support.v7.app.AlertDialog
import android.text.method.LinkMovementMethod
import android.view.LayoutInflater
import android.widget.TextView;
import groovy.transform.CompileStatic
import zhou.gank.io.R
import zhou.gank.io.comment.Config

@CompileStatic
public class InfoDialog extends DialogFragment {

    String title
    CharSequence content

    @Override
    void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)
        Bundle b = getArguments()
        title = b?.getString(Config.Static.TITLE)
        content = b?.getCharSequence(Config.Static.CONTENT)
    }

    @Override
    Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
        TextView tv = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text, null) as TextView
        tv.setText(content)
        tv.setMovementMethod(LinkMovementMethod.getInstance())
        builder.setTitle(title).setView(tv).setPositiveButton(R.string.confirm, null)
        AlertDialog dialog = builder.create()
        return dialog
    }

    static InfoDialog newInstance(String title, CharSequence content) {
        InfoDialog dialog = new InfoDialog()
        Bundle bundle = new Bundle()
        bundle.putString(Config.Static.TITLE, title)
        bundle.putCharSequence(Config.Static.CONTENT, content)
        dialog.setArguments(bundle)
        return dialog
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/fragment/AdvanceFragment.groovy
================================================
package zhou.gank.io.ui.fragment

import android.os.Bundle
import android.support.annotation.Nullable
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import groovy.transform.CompileStatic
import zhou.gank.io.R

@CompileStatic
public class AdvanceFragment extends BaseFragment {

    SwipeRefreshLayout swipeRefreshLayout
    RecyclerView recyclerView
    View error

    @Override
    View onCreateView(LayoutInflater inflater,
                      @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_recyler_view, container, false)
        initView(v)
        return v
    }

    @Override
    protected void initView(View v) {
        swipeRefreshLayout = v.findViewById(R.id.swipeRefreshLayout) as SwipeRefreshLayout
        recyclerView = v.findViewById(R.id.recyclerView) as RecyclerView

        swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_purple, android.R.color.holo_blue_bright, android.R.color.holo_orange_light,
                android.R.color.holo_red_light);


        swipeRefreshLayout.setOnRefreshListener(this.&requestRefresh)

        error = v.findViewById(R.id.error)

    }

    protected void onFailure() {
        swipeRefreshLayout.setRefreshing(false)
        error.setVisibility(View.VISIBLE)
    }

    protected void onSuccess() {
        swipeRefreshLayout.setRefreshing(false)
        recyclerView.setVisibility(View.VISIBLE)
        error.setVisibility(View.GONE)
    }

    protected void requestRefresh(View v = null) {
        swipeRefreshLayout.setRefreshing(true)
        error.setVisibility(View.GONE)
    }

}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/fragment/BaseFragment.groovy
================================================
package zhou.gank.io.ui.fragment

import android.app.Activity
import android.support.v4.app.Fragment
import android.support.v7.app.ActionBar
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.KeyEvent
import android.view.View
import groovy.transform.CompileStatic
import zhou.gank.io.util.Notifier

@CompileStatic
class BaseFragment extends Fragment {

    Notifier notifier

    @Override
    void onAttach(Activity activity) {
        super.onAttach(activity)
        if (activity instanceof Notifier) {
            notifier = activity as Notifier
        }
    }

    protected void setSupportActionBar(Toolbar toolbar) {
        Activity activity = getActivity();
        if (activity instanceof AppCompatActivity) {
            AppCompatActivity appCompatActivity = activity as AppCompatActivity;
            appCompatActivity.setSupportActionBar(toolbar);
        }
    }

    protected ActionBar getSupportActionBar() {
        Activity activity = getActivity();
        if (activity instanceof AppCompatActivity) {
            AppCompatActivity appCompatActivity = activity as AppCompatActivity;
            return appCompatActivity.getSupportActionBar();
        }
        return null;
    }

    protected void noticeActivity(int noticeId) {
        notifier?.notice(noticeId)
    }

    protected void initView(View v) {

    }

    protected void setTitle(String title) {
        getActivity().setTitle(title)
    }

    protected void setTitle(int res) {
        getActivity().setTitle(res)
    }

    boolean onKeyDown(int keyCode, KeyEvent event) {
        return false
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/fragment/DailyFragment.groovy
================================================
package zhou.gank.io.ui.fragment

import android.os.Bundle
import android.support.annotation.Nullable
import android.support.design.widget.CollapsingToolbarLayout
import android.support.design.widget.FloatingActionButton
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentPagerAdapter
import android.support.v4.view.PagerAdapter
import android.support.v4.view.ViewPager
import android.support.v7.app.ActionBar
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.Toolbar
import android.view.*
import android.widget.Toast
import groovy.transform.CompileStatic
import zhou.gank.io.R
import zhou.gank.io.comment.Config
import zhou.gank.io.data.DataManager
import zhou.gank.io.data.TimeProvider
import zhou.gank.io.model.Gank
import zhou.gank.io.model.GankDaily
import zhou.gank.io.ui.adapter.DailyAdapter
import zhou.gank.io.util.TimeKit

@CompileStatic
class DailyFragment extends BaseFragment {

    public static final int ID_REFRESH = 0x78901

//    ImageView icon;
    RecyclerView recyclerView;
    Toolbar toolbar;
    CollapsingToolbarLayout collapsingToolbarLayout;
    TimeProvider provider
    DailyAdapter dailyAdapter;
    ViewPager viewPager
    FloatingActionButton fab
    View loading, loadingProgress, empty, error
    boolean isMain = false
    int year, month, day
    int count
    MenuItem refresh


    @Override
    void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
        def b = getArguments()
        List<Integer> time = TimeKit.getTime()
        year = time[0]
        month = time[1]
        day = time[2]
        if (b) {
            year = b.getInt(Config.Static.YEAR, year)
            month = b.getInt(Config.Static.MONTH, month)
            day = b.getInt(Config.Static.DAY, day)
            isMain = b.getBoolean(Config.Static.IS_MAIN, false)
        }

        provider = new TimeProvider(year, month, day)
        provider.setNoticeable(true)
    }

    @Nullable
    @Override
    View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_daily, container, false);

        toolbar = view.findViewById(R.id.toolbar) as Toolbar
        collapsingToolbarLayout = view.findViewById(R.id.collapsing_toolbar) as CollapsingToolbarLayout
        recyclerView = view.findViewById(R.id.recyclerView) as RecyclerView
        viewPager = view.findViewById(R.id.viewpager) as ViewPager
        fab = view.findViewById(R.id.fab) as FloatingActionButton
        loading = view.findViewById(R.id.loading)
        loadingProgress = view.findViewById(R.id.progressBar)
        empty = view.findViewById(R.id.no_data)
        error = view.findViewById(R.id.error)

        setSupportActionBar(toolbar);
        ActionBar ab = getSupportActionBar();
        if (ab != null) {
            if (isMain)
                ab.setHomeAsUpIndicator(R.drawable.ic_menu_white_48px);
            ab.setDisplayHomeAsUpEnabled(true);
        }

        toolbar.setTitle(R.string.app_name);

        dailyAdapter = new DailyAdapter();

        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()))
        recyclerView.setAdapter(dailyAdapter)
        requestDaily()

        fab.setOnClickListener({ v ->
            noticeActivity(Config.Action.CHANGE_DATE)
        })

        error.setOnClickListener({ v ->
            requestDaily()
        })

        return view;
    }


    protected void setUpData(GankDaily daily) {
        if (daily != null) {
            if (daily.isEmpty()) {
                if (isMain) {
                    //为主页的情况
                    if (count > Config.Configurable.MAX_iteration) {
                        //重复加载次数过多(到达了底端)
                        setTitle(provider.year, provider.month, provider.day)
                        setEmpty()
                    } else {
                        //加载前一天的数据
                        if (count == 0) {
                            // 重新加载今天的内容
                            DataManager.getInstance().update(provider, this.&setUpData)
                            count++
                        } else {
                            count++
                            provider = provider.getPrevDay()
                            if (TimeKit.future(provider.year, provider.month, provider.day)) {
                                //如如果要加载的数据是今天或以后
                                DataManager.getInstance().update(provider, this.&setUpData)
                            } else {
                                DataManager.getInstance().get(provider, this.&setUpData)
                            }
                        }
                    }
                } else {
                    // Empty
                    setTitle(provider.year, provider.month, provider.day)
                    setEmpty()
                }
            } else {
                // Success
                setTitle(provider.year, provider.month, provider.day)
                List<List<Gank>> ganks = daily.ganks
                List<String> types = daily.types
                List<Gank> welfares = ganks.get(types.indexOf(Config.Type.WELFARE))
                int size = welfares?.size()
                Fragment[] fs = new Fragment[size]
                size.times {
                    int index = it as int
                    fs[index] = ImagePageFragment.newInstance(welfares.get(index).url)
                }

                PagerAdapter adapter = new FragmentPagerAdapter(getFragmentManager()) {
                    @Override
                    Fragment getItem(int i) {
                        fs[i]
                    }

                    @Override
                    int getCount() {
                        return fs.length
                    }
                } as PagerAdapter

                viewPager.setAdapter(adapter)

                dailyAdapter.setDaily(daily)

                setSuccess()
            }
        } else {
            // Error
            setTitle(provider.year, provider.month, provider.day)
            setError()
        }
        refresh?.setVisible(true)
    }

    @Override
    void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater)
        refresh = menu.add(0, ID_REFRESH, 0, R.string.text_refresh)
        refresh.setIcon(R.drawable.ic_refresh_48px)
        refresh.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
        refresh.setVisible(false)
    }

    @Override
    boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                if (isMain) {
                    noticeActivity(Config.Action.OPEN_DRAWER_LAYOUT)
                } else {
                    noticeActivity(Config.Action.FINISH)
                }
                return true;
            case ID_REFRESH:
                requestUpdate()
                return true
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void setTitle(String title) {
        collapsingToolbarLayout.setTitle(title);
    }

    def requestDaily() {
        setTitle(getString(R.string.loading))
        setLoading()
        refresh?.setVisible(false)
        requestData()
    }

    def requestUpdate() {
        setTitle(getString(R.string.loading))
        setLoading()
        refresh?.setVisible(false)
        DataManager.getInstance().update(provider, {
            setUpData(it as GankDaily)
            Toast.makeText(getActivity(),R.string.success_update,Toast.LENGTH_SHORT).show()
        })
    }

    def requestData() {
        DataManager.getInstance().get(provider, this.&setUpData)
    }

    def setLoading() {
        loading.setVisibility(View.VISIBLE)
        loadingProgress.setVisibility(View.VISIBLE)
        empty.setVisibility(View.GONE)
        error.setVisibility(View.GONE)
    }

    def setSuccess() {
        loading.setVisibility(View.INVISIBLE)
    }

    def setError() {
        loading.setVisibility(View.VISIBLE)
        loadingProgress.setVisibility(View.GONE)
        empty.setVisibility(View.INVISIBLE)
        error.setVisibility(View.VISIBLE)
    }

    def setEmpty() {
        loading.setVisibility(View.VISIBLE)
        loadingProgress.setVisibility(View.GONE)
        empty.setVisibility(View.VISIBLE)
        error.setVisibility(View.GONE)
    }

    protected void setTitle(int year, int month, int day) {
        setTitle("${year}${getString(R.string.year)}${month}${getString(R.string.month)}${day}${getString(R.string.day)}")
    }

    static DailyFragment newInstance(int year = -1, int month = -1, int day = -1, boolean isMain = false) {
        DailyFragment fragment = new DailyFragment()
        Bundle bundle = new Bundle()
        if (year > 0 && month > 0 && day > 0) {
            bundle.putInt(Config.Static.YEAR, year)
            bundle.putInt(Config.Static.MONTH, month)
            bundle.putInt(Config.Static.DAY, day)
        }
        bundle.putBoolean(Config.Static.IS_MAIN, isMain)
        fragment.setArguments(bundle)
        return fragment
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/fragment/GankFragment.groovy
================================================
package zhou.gank.io.ui.fragment

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.annotation.Nullable
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.Gravity
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.PopupMenu
import android.widget.ProgressBar
import android.widget.TextView
import android.widget.Toast
import groovy.transform.CompileStatic
import zhou.gank.io.R
import zhou.gank.io.comment.Config
import zhou.gank.io.data.CollectProvider
import zhou.gank.io.data.DataManager
import zhou.gank.io.data.DataProvider
import zhou.gank.io.data.RandomProvider
import zhou.gank.io.data.TypeProvider
import zhou.gank.io.database.DatabaseManager
import zhou.gank.io.model.Bookmark
import zhou.gank.io.model.Gank
import zhou.gank.io.ui.activity.ImageGalleryActivity
import zhou.gank.io.ui.activity.WebActivity
import zhou.gank.io.ui.adapter.BaseAdapter
import zhou.gank.io.ui.adapter.GankAdapter
import zhou.gank.io.ui.adapter.ImageAdapter
import zhou.gank.io.util.NumKit
import zhou.widget.AdvanceAdapter

@CompileStatic
public class GankFragment extends AdvanceFragment {

    DataProvider provider
    String type
    boolean isRandom, isImage, loadMoreProgress, isBookmark
    View more
    LinearLayoutManager manager
    ProgressBar progressBar
    TextView moreText
    private BaseAdapter adapter

    @Override
    void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)
        def b = getArguments()
        if (b) {
            type = b.getString(Config.Static.TYPE)
            isRandom = b.getBoolean(Config.Static.IS_RANDOM, false)
            isImage = b.getBoolean(Config.Static.IS_IMAGE, false)
            isBookmark = b.getBoolean(Config.Static.IS_BOOKMARK, false)
        }

        int size = NumKit.getNum(Config.getString(getString(R.string.key_num), "$Config.Configurable.DEFAULT_SIZE"), Config.Configurable.DEFAULT_SIZE)

        if (isBookmark) {
            provider = new CollectProvider()
        } else {
            if (isRandom) {
                provider = new RandomProvider(type, size)
            } else {
                provider = new TypeProvider(type, size)
            }
        }

        if (isImage) {
            adapter = new ImageAdapter()
        } else {
            adapter = new GankAdapter()
        }

        adapter.setClickListener { gank, p = null ->
            def gs = gank as Gank
            boolean flag = Config.getBoolean(getString(R.string.key_open), true)
            if (!flag) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(gs.url))
                startActivity(intent)
            } else {
                Intent intent
                if (isImage) {
                    intent = new Intent(getActivity(), ImageGalleryActivity.class)
                    ArrayList<Gank> ganks = provider.get() as ArrayList<Gank>
                    ArrayList<String> urls = new ArrayList<>(ganks.size())
                    ganks.each {
                        urls << it.url
                    }
                    intent.putStringArrayListExtra(Config.Static.URLS, urls)
                    intent.putExtra(Config.Static.POSITION, p as int)
                } else {
                    intent = new Intent(getActivity(), WebActivity.class)
                    intent.putExtra(Config.Static.URL, gs.url)
                    intent.putExtra(Config.Static.TITLE, gs.desc)
                }
                startActivity(intent)
            }
        }

        if (isBookmark) {
            adapter.setLongClickListener { v, gank, p ->
                def g = gank as Gank
                def view = v as View
                PopupMenu popupMenu = new PopupMenu(getActivity(), view, Gravity.END)
                Menu menu = popupMenu.getMenu()
                popupMenu.getMenuInflater().inflate(R.menu.menu_pop, menu)
                popupMenu.setOnMenuItemClickListener({ item ->
                    def i = item as MenuItem
                    switch (i.getItemId()) {
                        case R.id.menu_delete:
                            DatabaseManager.getInstance().delete(g.url)
                            adapter.removeItem(p as int)
                            Toast.makeText(getActivity(), R.string.success_delete, Toast.LENGTH_SHORT).show()
                            return true
                    }
                    return false
                })
                popupMenu.show()
                return true
            }
        } else {
            adapter.setLongClickListener { v, gank, p ->
                def g = gank as Gank
                def view = v as View
                PopupMenu popupMenu = new PopupMenu(getActivity(), view, Gravity.END)
                Menu menu = popupMenu.getMenu()
                if (DatabaseManager.getInstance().isExist(g.url)) {
                    popupMenu.getMenuInflater().inflate(R.menu.menu_pop_remove, menu)
                } else {
                    popupMenu.getMenuInflater().inflate(R.menu.menu_pop_add, menu)
                }
                popupMenu.setOnMenuItemClickListener({ item ->
                    def i = item as MenuItem
                    switch (i.getItemId()) {
                        case R.id.menu_add:
                            DatabaseManager.getInstance().insert(new Bookmark(g.url, g.desc))
                            Toast.makeText(getActivity(), R.string.success_collect, Toast.LENGTH_SHORT).show()
                            return true
                        case R.id.menu_remove:
                            DatabaseManager.getInstance().delete(g.url)
                            Toast.makeText(getActivity(), R.string.success_uncollect, Toast.LENGTH_SHORT).show()
                            return true
                    }
                    return false
                })
                popupMenu.show()
                return true
            }
        }


    }


    public void setUpData(List<Gank> ganks) {
        if (ganks != null) {
            if (ganks.isEmpty()) {
                onNoMoreData()
                Toast.makeText(getActivity(), R.string.no_data, Toast.LENGTH_SHORT).show()
            } else {
                onSuccess()
                adapter.setGanks(ganks)
                showMore()
            }
        } else {
            onLoadFailure()
            onFailure()
        }
    }


    @Override
    protected void initView(View v) {
        super.initView(v)

        manager = new LinearLayoutManager(getActivity())
        recyclerView.setLayoutManager(manager)

        if (!isRandom) {
            more = LayoutInflater.from(getActivity()).inflate(R.layout.layout_more, null)
            moreText = more.findViewById(R.id.textView) as TextView
            progressBar = more.findViewById(R.id.progressBar) as ProgressBar

            AdvanceAdapter advanceAdapter = new AdvanceAdapter(adapter)
            advanceAdapter.addFooter(more)
            recyclerView.setAdapter(advanceAdapter)

            recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                        if (more.isShown()) {
                            more()
                        }
//                        if (manager.findLastVisibleItemPosition() == advanceAdapter.getItemCount() - 1) {
//                            more();
//                        }
                    }
                }

                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                }
            });

            more.setVisibility(View.GONE)
            more.setClickable(false)

            more.setOnClickListener(this.&more)

        } else {
            recyclerView.setAdapter(adapter)
        }

        if (isBookmark) {
            swipeRefreshLayout.setEnabled(false)
        }

        swipeRefreshLayout.setRefreshing(true)
        provider.setNoticeable(true)
        DataManager.getInstance().get(provider, this.&setUpData)

        error.setOnClickListener({ view ->
            swipeRefreshLayout.setRefreshing(true)
            error.setVisibility(View.GONE)
            requestRefresh()
        })

    }

    @Override
    void onDestroyView() {
        super.onDestroyView()
        provider.setNoticeable(false)
    }

    @Override
    void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden)
        provider.setNoticeable(!hidden)
    }

    @Override
    protected void requestRefresh() {
        super.requestRefresh()
        DataManager.getInstance().update(provider, this.&setUpData)
    }

    protected void more(View v = null) {
        if (loadMoreProgress) {
            return
        }
        loadMoreProgress = true
        onLoading()
        DataManager.getInstance().more(provider, { ganks ->
            setUpData(ganks as List<Gank>)
            loadMoreProgress = false
        })
    }

    def onNoMoreData() {
        moreText?.setText(R.string.more_last)
        progressBar?.setVisibility(View.INVISIBLE)
        more?.setClickable(false)
    }

    def onLoading() {
        moreText?.setText(R.string.text_loading)
        progressBar?.setVisibility(View.VISIBLE)
        more?.setClickable(false)
    }

    def onLoadFailure() {
        moreText?.setText(R.string.text_loading_failure)
        progressBar?.setVisibility(View.VISIBLE)
        more?.setClickable(true)
    }

    protected void showMore() {
        if (manager.getItemCount() > manager.findLastVisibleItemPosition() - manager.findFirstVisibleItemPosition() + 1)
            more?.setVisibility(View.VISIBLE)
    }

    static GankFragment newInstance(String type, boolean isRandom = false, boolean isImage = false, boolean isBookmark = false) {
        GankFragment fragment = new GankFragment()
        Bundle bundle = new Bundle()
        bundle.putString(Config.Static.TYPE, type)
        bundle.putBoolean(Config.Static.IS_RANDOM, isRandom)
        bundle.putBoolean(Config.Static.IS_IMAGE, isImage)
        bundle.putBoolean(Config.Static.IS_BOOKMARK, isBookmark)
        fragment.setArguments(bundle)
        fragment
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/fragment/ImageFragment.groovy
================================================
package zhou.gank.io.ui.fragment

import android.os.Bundle
import android.support.annotation.Nullable
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import android.widget.Toast
import groovy.transform.CompileStatic
import zhou.gank.io.comment.Config
import zhou.gank.io.data.DataProvider
import zhou.gank.io.data.RandomProvider
import zhou.gank.io.data.TypeProvider
import zhou.gank.io.model.Gank
import zhou.gank.io.ui.adapter.ImageAdapter

@CompileStatic
public class ImageFragment extends AdvanceFragment {

    ImageAdapter adapter
    LinearLayoutManager manager
    DataProvider provider
    boolean isRandom
    String type
    View more

    @Override
    void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)

        def b = getArguments()
        if (b) {
            type = b.getString(Config.Static.TYPE)
            isRandom = b.getBoolean(Config.Static.IS_RANDOM, false)
        }

        if (isRandom) {
            provider = new RandomProvider(type, Config.Configurable.DEFAULT_SIZE)
        } else {
            provider = new TypeProvider(type, Config.Configurable.DEFAULT_SIZE)
        }
        adapter = new ImageAdapter()
    }

    public void setUpData(List<Gank> ganks) {
        if (ganks != null) {
            if (ganks.isEmpty()) {
                hiddenMore()
                Toast.makeText(getActivity(), "empty", Toast.LENGTH_SHORT).show()
            } else {
                onSuccess()
                adapter.setGanks(ganks)
            }
        } else {
            onFailure()
        }
    }

    protected void hiddenMore() {
        more?.setVisibility(View.GONE)
    }

    @Override
    protected void initView(View v) {
        super.initView(v)

        manager = new LinearLayoutManager(getActivity())
        recyclerView.setLayoutManager(manager)


    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/fragment/ImageGalleryFragment.groovy
================================================
package zhou.gank.io.ui.fragment

import android.content.Intent
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import android.support.annotation.Nullable
import android.support.v4.view.ViewPager
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.squareup.picasso.Picasso
import com.squareup.picasso.Target;
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.comment.Config
import zhou.gank.io.ui.adapter.ImageGalleryAdapter
import zhou.gank.io.util.FileKit

@CompileStatic
public class ImageGalleryFragment extends BaseFragment {

    public static final int ID_SHARE = 0x23456
    public static final int ID_SAVE = 0x34567

    List<String> urls
    int position
    ViewPager viewPager

    @Override
    void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)
        setHasOptionsMenu(true)
        def b = getArguments()
        urls = b?.getStringArrayList(Config.Static.URLS)
        position = b?.getInt(Config.Static.POSITION, 0)
        setTitle("${position + 1}/${urls == null ? 0 : urls.size()}")
    }

    @Override
    View onCreateView(LayoutInflater inflater,
                      @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        viewPager = inflater.inflate(R.layout.fragment_viewpager, container, false) as ViewPager
        ImageGalleryAdapter adapter = new ImageGalleryAdapter(urls)
        viewPager.setAdapter(adapter)
        viewPager.setCurrentItem(position, false)

        viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            void onPageSelected(int position) {
                setTitle("${position + 1}/${urls == null ? 0 : urls.size()}")
            }
        })
        return viewPager
    }

    @Override
    void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater)
        menu.add(0, ID_SHARE, 0, R.string.share)
        menu.add(0, ID_SAVE, 0, R.string.save)
    }

    @Override
    boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case ID_SHARE:
                String url = urls?.get(viewPager.getCurrentItem())
                Picasso.with(getActivity()).load(url).into(new Target() {
                    @Override
                    void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                        File file = new File(App.getInstance().getExternalCacheDir(), "temp.jpg")
                        FileKit.saveBitmapFile(bitmap, file)
                        Intent intent = new Intent(Intent.ACTION_SEND)
                        intent.setType("image/*")
                        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file))
                        startActivity(intent)
                    }

                    @Override
                    void onBitmapFailed(Drawable errorDrawable) {
                        Toast.makeText(getActivity(), R.string.error_get_image, Toast.LENGTH_SHORT).show()
                    }

                    @Override
                    void onPrepareLoad(Drawable placeHolderDrawable) {

                    }
                })
                return true
            case ID_SAVE:
                String url = urls?.get(viewPager.getCurrentItem())
                File file = new File(App.SAVE_PATH, FileKit.getFileRealName(url))
                Picasso.with(getActivity()).load(url).into(new Target() {
                    @Override
                    void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                        FileKit.saveBitmapFile(bitmap, file)
                        Toast.makeText(getActivity(), "图片保存在:${file.getAbsolutePath()}", Toast.LENGTH_LONG).show()
                    }

                    @Override
                    void onBitmapFailed(Drawable errorDrawable) {
                        Toast.makeText(getActivity(), R.string.error_get_image, Toast.LENGTH_SHORT).show()
                    }

                    @Override
                    void onPrepareLoad(Drawable placeHolderDrawable) {

                    }
                })
                return true
        }
        return super.onOptionsItemSelected(item)
    }

    static ImageGalleryFragment newInstance(ArrayList<String> urls, int position = 0) {
        ImageGalleryFragment fragment = new ImageGalleryFragment()
        Bundle bundle = new Bundle()
        bundle.putStringArrayList(Config.Static.URLS, urls)
        bundle.putInt(Config.Static.POSITION, position)
        fragment.setArguments(bundle)
        return fragment
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/fragment/ImagePageFragment.groovy
================================================
package zhou.gank.io.ui.fragment

import android.content.Intent
import android.os.Bundle
import android.support.annotation.Nullable
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.squareup.picasso.Picasso;
import groovy.transform.CompileStatic
import zhou.gank.io.R
import zhou.gank.io.comment.Config
import zhou.gank.io.ui.activity.ImageGalleryActivity

@CompileStatic
public class ImagePageFragment extends Fragment {

    @Override
    View onCreateView(LayoutInflater inflater,
                      @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ImageView icon = inflater.inflate(R.layout.fragment_image_page, container, false) as ImageView
        icon.setClickable(true)
        def b = getArguments()
        if (b) {
            String url = b.getString(Config.Static.URL)
            Picasso.with(getActivity()).load(url).into(icon)
            icon.setOnClickListener({ v ->
                if (icon.getDrawable()) {
                    ArrayList<String> urls = new ArrayList<>(1)
                    urls << url
                    Intent intent = new Intent(getActivity(), ImageGalleryActivity.class)
                    intent.putStringArrayListExtra(Config.Static.URLS, urls)
                    intent.putExtra(Config.Static.POSITION, 0)
                    startActivity(intent)
                }
            })
        }
        return icon
    }


    static ImagePageFragment newInstance(String url) {
        ImagePageFragment imagePageFragment = new ImagePageFragment()
        Bundle bundle = new Bundle()
        bundle.putString(Config.Static.URL, url)
        imagePageFragment.setArguments(bundle)
        return imagePageFragment
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/fragment/SettingFragment.groovy
================================================
package zhou.gank.io.ui.fragment

import android.os.Bundle
import android.preference.ListPreference
import android.preference.Preference
import android.preference.PreferenceFragment
import android.preference.PreferenceScreen
import android.widget.Toast;
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R

@CompileStatic
public class SettingFragment extends PreferenceFragment {

    @Override
    void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)
        addPreferencesFromResource(R.xml.setting)

        ListPreference themes = findPreference(getString(R.string.key_theme)) as ListPreference
        themes.setOnPreferenceChangeListener({ preference, o ->
            App.themeChanged()
            getActivity().recreate()
            Toast.makeText(getActivity(), "设置成功", Toast.LENGTH_SHORT).show()
            return true
        })
    }

    @Override
    boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
        switch (preference.getKey()) {
            case getString(R.string.key_clear):
                def g = App.cacheFile().deleteDir()
                if (g) {
                    App.toast(R.string.success_clear)
                }
        }
        return super.onPreferenceTreeClick(preferenceScreen, preference)
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/fragment/WebFragment.groovy
================================================
package zhou.gank.io.ui.fragment

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.annotation.Nullable
import android.support.v4.widget.SwipeRefreshLayout
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.ProgressBar
import android.widget.Toast
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.comment.Config
import zhou.gank.io.database.DatabaseManager
import zhou.gank.io.model.Bookmark
import zhou.gank.io.util.LogKit

@CompileStatic
public class WebFragment extends BaseFragment {

    WebView webView
    String url, title
    ProgressBar progressBar
    SwipeRefreshLayout swipeRefreshLayout
    MenuItem itemCollect

    @Override
    void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState)
        setHasOptionsMenu(true)
    }

    @Override
    View onCreateView(LayoutInflater inflater,
                      @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_web, container, false)
        initView(v)
        return v
    }

    @Override
    protected void initView(View v) {
        webView = v.findViewById(R.id.web_view) as WebView
        progressBar = v.findViewById(R.id.progressBar) as ProgressBar
        swipeRefreshLayout = v.findViewById(R.id.swipeRefreshLayout) as SwipeRefreshLayout

        swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_purple, android.R.color.holo_blue_bright, android.R.color.holo_orange_light,
                android.R.color.holo_red_light);

        webView.getSettings().setJavaScriptEnabled(true)

        Bundle bundle = getArguments()
        url = bundle?.getString(Config.Static.URL)
        title = bundle?.getString(Config.Static.TITLE)

        webView.loadUrl(url)

        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    // 网页加载完成
                    progressBar.setVisibility(View.GONE)
                    progressBar.setProgress(0)
                    swipeRefreshLayout.setRefreshing(false)
                } else {
                    // 加载中
                    progressBar.setVisibility(View.VISIBLE)
                    progressBar.setProgress(newProgress)
                }
            }

            @Override
            void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title)
                getActivity()?.setTitle(title)
            }
        });

        webView.setWebViewClient(new WebViewClient() {

            @Override
            boolean shouldOverrideUrlLoading(WebView view, String url) {
                webView.loadUrl(url)
                return true
            }
        })

        webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        webView.getSettings().setSupportZoom(true)
        webView.getSettings().setDisplayZoomControls(true)

        swipeRefreshLayout.setOnRefreshListener({
            webView.reload()
        })
    }

    @Override
    boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (webView.canGoBack()) {
                webView.goBack()//返回上一页面
                return true
            } else {
                getActivity().finish()
                return true
            }
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater)
        inflater.inflate(R.menu.menu_web, menu)
        itemCollect = menu.findItem(R.id.menu_collect)
        if (DatabaseManager.getInstance().isExist(url)) {
            itemCollect.setTitle(R.string.cancel_collect)
        } else {
            itemCollect.setTitle(R.string.menu_collect)
        }
    }

    @Override
    boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_copy:
                App.copyUri(Uri.parse(url))
                App.toast(R.string.success_copy)
                return true
            case R.id.menu_open:
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url))
                startActivity(intent)
                return true
            case R.id.menu_collect:
                collect()
                return true
        }
        return super.onOptionsItemSelected(item)
    }

    def collect() {
        if (DatabaseManager.getInstance().isExist(url)) {
            try {
                DatabaseManager.getInstance().delete(url)
                Toast.makeText(getActivity(), R.string.success_uncollect, Toast.LENGTH_SHORT).show()
                itemCollect.setTitle(R.string.menu_collect)
            } catch (Exception e) {
                LogKit.d("uncollect", "failure", e)
                Toast.makeText(getActivity(), R.string.failure_uncollect, Toast.LENGTH_SHORT).show()
            }
        } else {
            try {
                DatabaseManager.getInstance().insert(new Bookmark(url, title == getString(R.string.app_name) ? webView.getTitle() : title))
                Toast.makeText(getActivity(), R.string.success_collect, Toast.LENGTH_SHORT).show()
                itemCollect.setTitle(R.string.cancel_collect)
            } catch (Exception e) {
                LogKit.d("collect", "failure", e)
                Toast.makeText(getActivity(), R.string.failure_collect, Toast.LENGTH_SHORT).show()
            }
        }
    }

    static WebFragment newInstance(String url, String title = null) {
        WebFragment webFragment = new WebFragment()
        Bundle bundle = new Bundle()
        bundle.putString(Config.Static.URL, url)
        bundle.putString(Config.Static.TITLE, title)
        webFragment.setArguments(bundle)
        return webFragment
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/weiget/SwipeToRefreshLayout.groovy
================================================
package zhou.gank.io.ui.weiget

import android.content.Context
import android.support.v4.widget.SwipeRefreshLayout
import android.util.AttributeSet;
import groovy.transform.CompileStatic

@CompileStatic
public class SwipeToRefreshLayout extends SwipeRefreshLayout{

    SwipeToRefreshLayout(Context context) {
        super(context)
    }

    SwipeToRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs)
    }

    private boolean mMeasured = false;
    private boolean mPreMeasureRefreshing = false;

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (!mMeasured) {
            mMeasured = true
            setRefreshing(mPreMeasureRefreshing)
        }
    }


    @Override
    public void setRefreshing(boolean refreshing) {
        if (mMeasured) {
            super.setRefreshing(refreshing)
        } else {
            mPreMeasureRefreshing = refreshing
        }
    }

}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/weiget/TouchImageView.java
================================================
package zhou.gank.io.ui.weiget;


/*
 * TouchImageView.java
 * By: Michael Ortiz
 * Updated By: Patrick Lackemacher
 * Updated By: Babay88
 * Updated By: @ipsilondev
 * Updated By: hank-cp
 * Updated By: singpolyma
 * -------------------
 * Extends Android ImageView to include pinch zooming, panning, fling and double tap zoom.
 */


import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;
import android.widget.OverScroller;
import android.widget.Scroller;

public class TouchImageView extends ImageView {

    private static final String DEBUG = "DEBUG";

    //
    // SuperMin and SuperMax multipliers. Determine how much the image can be
    // zoomed below or above the zoom boundaries, before animating back to the
    // min/max zoom boundary.
    //
    private static final float SUPER_MIN_MULTIPLIER = .75f;
    private static final float SUPER_MAX_MULTIPLIER = 1.25f;

    //
    // Scale of image ranges from minScale to maxScale, where minScale == 1
    // when the image is stretched to fit view.
    //
    private float normalizedScale;

    //
    // Matrix applied to image. MSCALE_X and MSCALE_Y should always be equal.
    // MTRANS_X and MTRANS_Y are the other values used. prevMatrix is the matrix
    // saved prior to the screen rotating.
    //
    private Matrix matrix, prevMatrix;

    private enum State {NONE, DRAG, ZOOM, FLING, ANIMATE_ZOOM}

    private State state;

    private float minScale;
    private float maxScale;
    private float superMinScale;
    private float superMaxScale;
    private float[] m;

    private Context context;
    private Fling fling;

    private ScaleType mScaleType;

    private boolean imageRenderedAtLeastOnce;
    private boolean onDrawReady;

    private ZoomVariables delayedZoomVariables;

    //
    // Size of view and previous view size (ie before rotation)
    //
    private int viewWidth, viewHeight, prevViewWidth, prevViewHeight;

    //
    // Size of image when it is stretched to fit view. Before and After rotation.
    //
    private float matchViewWidth, matchViewHeight, prevMatchViewWidth, prevMatchViewHeight;

    private ScaleGestureDetector mScaleDetector;
    private GestureDetector mGestureDetector;
    private GestureDetector.OnDoubleTapListener doubleTapListener = null;
    private OnTouchListener userTouchListener = null;
    private OnTouchImageViewListener touchImageViewListener = null;

    public TouchImageView(Context context) {
        super(context);
        sharedConstructing(context);
    }

    public TouchImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        sharedConstructing(context);
    }

    public TouchImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        sharedConstructing(context);
    }

    private void sharedConstructing(Context context) {
        super.setClickable(true);
        this.context = context;
        mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
        mGestureDetector = new GestureDetector(context, new GestureListener());
        matrix = new Matrix();
        prevMatrix = new Matrix();
        m = new float[9];
        normalizedScale = 1;
        if (mScaleType == null) {
            mScaleType = ScaleType.FIT_CENTER;
        }
        minScale = 1;
        maxScale = 3;
        superMinScale = SUPER_MIN_MULTIPLIER * minScale;
        superMaxScale = SUPER_MAX_MULTIPLIER * maxScale;
        setImageMatrix(matrix);
        setScaleType(ScaleType.MATRIX);
        setState(State.NONE);
        onDrawReady = false;
        super.setOnTouchListener(new PrivateOnTouchListener());
    }

    @Override
    public void setOnTouchListener(OnTouchListener l) {
        userTouchListener = l;
    }

    public void setOnTouchImageViewListener(OnTouchImageViewListener l) {
        touchImageViewListener = l;
    }

    public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener l) {
        doubleTapListener = l;
    }

    @Override
    public void setImageResource(int resId) {
        super.setImageResource(resId);
        savePreviousImageValues();
        fitImageToView();
    }

    @Override
    public void setImageBitmap(Bitmap bm) {
        super.setImageBitmap(bm);
        savePreviousImageValues();
        fitImageToView();
    }

    @Override
    public void setImageDrawable(Drawable drawable) {
        super.setImageDrawable(drawable);
        savePreviousImageValues();
        fitImageToView();
    }

    @Override
    public void setImageURI(Uri uri) {
        super.setImageURI(uri);
        savePreviousImageValues();
        fitImageToView();
    }

    @Override
    public void setScaleType(ScaleType type) {
        if (type == ScaleType.FIT_START || type == ScaleType.FIT_END) {
            throw new UnsupportedOperationException("TouchImageView does not support FIT_START or FIT_END");
        }
        if (type == ScaleType.MATRIX) {
            super.setScaleType(ScaleType.MATRIX);

        } else {
            mScaleType = type;
            if (onDrawReady) {
                //
                // If the image is already rendered, scaleType has been called programmatically
                // and the TouchImageView should be updated with the new scaleType.
                //
                setZoom(this);
            }
        }
    }

    @Override
    public ScaleType getScaleType() {
        return mScaleType;
    }

    /**
     * Returns false if image is in initial, unzoomed state. False, otherwise.
     *
     * @return true if image is zoomed
     */
    public boolean isZoomed() {
        return normalizedScale != 1;
    }

    /**
     * Return a Rect representing the zoomed image.
     *
     * @return rect representing zoomed image
     */
    public RectF getZoomedRect() {
        if (mScaleType == ScaleType.FIT_XY) {
            throw new UnsupportedOperationException("getZoomedRect() not supported with FIT_XY");
        }
        PointF topLeft = transformCoordTouchToBitmap(0, 0, true);
        PointF bottomRight = transformCoordTouchToBitmap(viewWidth, viewHeight, true);

        float w = getDrawable().getIntrinsicWidth();
        float h = getDrawable().getIntrinsicHeight();
        return new RectF(topLeft.x / w, topLeft.y / h, bottomRight.x / w, bottomRight.y / h);
    }

    /**
     * Save the current matrix and view dimensions
     * in the prevMatrix and prevView variables.
     */
    private void savePreviousImageValues() {
        if (matrix != null && viewHeight != 0 && viewWidth != 0) {
            matrix.getValues(m);
            prevMatrix.setValues(m);
            prevMatchViewHeight = matchViewHeight;
            prevMatchViewWidth = matchViewWidth;
            prevViewHeight = viewHeight;
            prevViewWidth = viewWidth;
        }
    }

    @Override
    public Parcelable onSaveInstanceState() {
        Bundle bundle = new Bundle();
        bundle.putParcelable("instanceState", super.onSaveInstanceState());
        bundle.putFloat("saveScale", normalizedScale);
        bundle.putFloat("matchViewHeight", matchViewHeight);
        bundle.putFloat("matchViewWidth", matchViewWidth);
        bundle.putInt("viewWidth", viewWidth);
        bundle.putInt("viewHeight", viewHeight);
        matrix.getValues(m);
        bundle.putFloatArray("matrix", m);
        bundle.putBoolean("imageRendered", imageRenderedAtLeastOnce);
        return bundle;
    }

    @Override
    public void onRestoreInstanceState(Parcelable state) {
        if (state instanceof Bundle) {
            Bundle bundle = (Bundle) state;
            normalizedScale = bundle.getFloat("saveScale");
            m = bundle.getFloatArray("matrix");
            prevMatrix.setValues(m);
            prevMatchViewHeight = bundle.getFloat("matchViewHeight");
            prevMatchViewWidth = bundle.getFloat("matchViewWidth");
            prevViewHeight = bundle.getInt("viewHeight");
            prevViewWidth = bundle.getInt("viewWidth");
            imageRenderedAtLeastOnce = bundle.getBoolean("imageRendered");
            super.onRestoreInstanceState(bundle.getParcelable("instanceState"));
            return;
        }

        super.onRestoreInstanceState(state);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        onDrawReady = true;
        imageRenderedAtLeastOnce = true;
        if (delayedZoomVariables != null) {
            setZoom(delayedZoomVariables.scale, delayedZoomVariables.focusX, delayedZoomVariables.focusY, delayedZoomVariables.scaleType);
            delayedZoomVariables = null;
        }
        super.onDraw(canvas);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        savePreviousImageValues();
    }

    /**
     * Get the max zoom multiplier.
     *
     * @return max zoom multiplier.
     */
    public float getMaxZoom() {
        return maxScale;
    }

    /**
     * Set the max zoom multiplier. Default value: 3.
     *
     * @param max max zoom multiplier.
     */
    public void setMaxZoom(float max) {
        maxScale = max;
        superMaxScale = SUPER_MAX_MULTIPLIER * maxScale;
    }

    /**
     * Get the min zoom multiplier.
     *
     * @return min zoom multiplier.
     */
    public float getMinZoom() {
        return minScale;
    }

    /**
     * Get the current zoom. This is the zoom relative to the initial
     * scale, not the original resource.
     *
     * @return current zoom multiplier.
     */
    public float getCurrentZoom() {
        return normalizedScale;
    }

    /**
     * Set the min zoom multiplier. Default value: 1.
     *
     * @param min min zoom multiplier.
     */
    public void setMinZoom(float min) {
        minScale = min;
        superMinScale = SUPER_MIN_MULTIPLIER * minScale;
    }

    /**
     * Reset zoom and translation to initial state.
     */
    public void resetZoom() {
        normalizedScale = 1;
        fitImageToView();
    }

    /**
     * Set zoom to the specified scale. Image will be centered by default.
     *
     * @param scale
     */
    public void setZoom(float scale) {
        setZoom(scale, 0.5f, 0.5f);
    }

    /**
     * Set zoom to the specified scale. Image will be centered around the point
     * (focusX, focusY). These floats range from 0 to 1 and denote the focus point
     * as a fraction from the left and top of the view. For example, the top left
     * corner of the image would be (0, 0). And the bottom right corner would be (1, 1).
     *
     * @param scale
     * @param focusX
     * @param focusY
     */
    public void setZoom(float scale, float focusX, float focusY) {
        setZoom(scale, focusX, focusY, mScaleType);
    }

    /**
     * Set zoom to the specified scale. Image will be centered around the point
     * (focusX, focusY). These floats range from 0 to 1 and denote the focus point
     * as a fraction from the left and top of the view. For example, the top left
     * corner of the image would be (0, 0). And the bottom right corner would be (1, 1).
     *
     * @param scale
     * @param focusX
     * @param focusY
     * @param scaleType
     */
    public void setZoom(float scale, float focusX, float focusY, ScaleType scaleType) {
        //
        // setZoom can be called before the image is on the screen, but at this point,
        // image and view sizes have not yet been calculated in onMeasure. Thus, we should
        // delay calling setZoom until the view has been measured.
        //
        if (!onDrawReady) {
            delayedZoomVariables = new ZoomVariables(scale, focusX, focusY, scaleType);
            return;
        }

        if (scaleType != mScaleType) {
            setScaleType(scaleType);
        }
        resetZoom();
        scaleImage(scale, viewWidth / 2, viewHeight / 2, true);
        matrix.getValues(m);
        m[Matrix.MTRANS_X] = -((focusX * getImageWidth()) - (viewWidth * 0.5f));
        m[Matrix.MTRANS_Y] = -((focusY * getImageHeight()) - (viewHeight * 0.5f));
        matrix.setValues(m);
        fixTrans();
        setImageMatrix(matrix);
    }

    /**
     * Set zoom parameters equal to another TouchImageView. Including scale, position,
     * and ScaleType.
     *
     * @param TouchImageView
     */
    public void setZoom(TouchImageView img) {
        PointF center = img.getScrollPosition();
        setZoom(img.getCurrentZoom(), center.x, center.y, img.getScaleType());
    }

    /**
     * Return the point at the center of the zoomed image. The PointF coordinates range
     * in value between 0 and 1 and the focus point is denoted as a fraction from the left
     * and top of the view. For example, the top left corner of the image would be (0, 0).
     * And the bottom right corner would be (1, 1).
     *
     * @return PointF representing the scroll position of the zoomed image.
     */
    public PointF getScrollPosition() {
        Drawable drawable = getDrawable();
        if (drawable == null) {
            return null;
        }
        int drawableWidth = drawable.getIntrinsicWidth();
        int drawableHeight = drawable.getIntrinsicHeight();

        PointF point = transformCoordTouchToBitmap(viewWidth / 2, viewHeight / 2, true);
        point.x /= drawableWidth;
        point.y /= drawableHeight;
        return point;
    }

    /**
     * Set the focus point of the zoomed image. The focus points are denoted as a fraction from the
     * left and top of the view. The focus points can range in value between 0 and 1.
     *
     * @param focusX
     * @param focusY
     */
    public void setScrollPosition(float focusX, float focusY) {
        setZoom(normalizedScale, focusX, focusY);
    }

    /**
     * Performs boundary checking and fixes the image matrix if it
     * is out of bounds.
     */
    private void fixTrans() {
        matrix.getValues(m);
        float transX = m[Matrix.MTRANS_X];
        float transY = m[Matrix.MTRANS_Y];

        float fixTransX = getFixTrans(transX, viewWidth, getImageWidth());
        float fixTransY = getFixTrans(transY, viewHeight, getImageHeight());

        if (fixTransX != 0 || fixTransY != 0) {
            matrix.postTranslate(fixTransX, fixTransY);
        }
    }

    /**
     * When transitioning from zooming from focus to zoom from center (or vice versa)
     * the image can become unaligned within the view. This is apparent when zooming
     * quickly. When the content size is less than the view size, the content will often
     * be centered incorrectly within the view. fixScaleTrans first calls fixTrans() and
     * then makes sure the image is centered correctly within the view.
     */
    private void fixScaleTrans() {
        fixTrans();
        matrix.getValues(m);
        if (getImageWidth() < viewWidth) {
            m[Matrix.MTRANS_X] = (viewWidth - getImageWidth()) / 2;
        }

        if (getImageHeight() < viewHeight) {
            m[Matrix.MTRANS_Y] = (viewHeight - getImageHeight()) / 2;
        }
        matrix.setValues(m);
    }

    private float getFixTrans(float trans, float viewSize, float contentSize) {
        float minTrans, maxTrans;

        if (contentSize <= viewSize) {
            minTrans = 0;
            maxTrans = viewSize - contentSize;

        } else {
            minTrans = viewSize - contentSize;
            maxTrans = 0;
        }

        if (trans < minTrans)
            return -trans + minTrans;
        if (trans > maxTrans)
            return -trans + maxTrans;
        return 0;
    }

    private float getFixDragTrans(float delta, float viewSize, float contentSize) {
        if (contentSize <= viewSize) {
            return 0;
        }
        return delta;
    }

    private float getImageWidth() {
        return matchViewWidth * normalizedScale;
    }

    private float getImageHeight() {
        return matchViewHeight * normalizedScale;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        Drawable drawable = getDrawable();
        if (drawable == null || drawable.getIntrinsicWidth() == 0 || drawable.getIntrinsicHeight() == 0) {
            setMeasuredDimension(0, 0);
            return;
        }

        int drawableWidth = drawable.getIntrinsicWidth();
        int drawableHeight = drawable.getIntrinsicHeight();
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        viewWidth = setViewSize(widthMode, widthSize, drawableWidth);
        viewHeight = setViewSize(heightMode, heightSize, drawableHeight);

        //
        // Set view dimensions
        //
        setMeasuredDimension(viewWidth, viewHeight);

        //
        // Fit content within view
        //
        fitImageToView();
    }

    /**
     * If the normalizedScale is equal to 1, then the image is made to fit the screen. Otherwise,
     * it is made to fit the screen according to the dimensions of the previous image matrix. This
     * allows the image to maintain its zoom after rotation.
     */
    private void fitImageToView() {
        Drawable drawable = getDrawable();
        if (drawable == null || drawable.getIntrinsicWidth() == 0 || drawable.getIntrinsicHeight() == 0) {
            return;
        }
        if (matrix == null || prevMatrix == null) {
            return;
        }

        int drawableWidth = drawable.getIntrinsicWidth();
        int drawableHeight = drawable.getIntrinsicHeight();

        //
        // Scale image for view
        //
        float scaleX = (float) viewWidth / drawableWidth;
        float scaleY = (float) viewHeight / drawableHeight;

        switch (mScaleType) {
            case CENTER:
                scaleX = scaleY = 1;
                break;

            case CENTER_CROP:
                scaleX = scaleY = Math.max(scaleX, scaleY);
                break;

            case CENTER_INSIDE:
                scaleX = scaleY = Math.min(1, Math.min(scaleX, scaleY));

            case FIT_CENTER:
                scaleX = scaleY = Math.min(scaleX, scaleY);
                break;

            case FIT_XY:
                break;

            default:
                //
                // FIT_START and FIT_END not supported
                //
                throw new UnsupportedOperationException("TouchImageView does not support FIT_START or FIT_END");

        }

        //
        // Center the image
        //
        float redundantXSpace = viewWidth - (scaleX * drawableWidth);
        float redundantYSpace = viewHeight - (scaleY * drawableHeight);
        matchViewWidth = viewWidth - redundantXSpace;
        matchViewHeight = viewHeight - redundantYSpace;
        if (!isZoomed() && !imageRenderedAtLeastOnce) {
            //
            // Stretch and center image to fit view
            //
            matrix.setScale(scaleX, scaleY);
            matrix.postTranslate(redundantXSpace / 2, redundantYSpace / 2);
            normalizedScale = 1;

        } else {
            //
            // These values should never be 0 or we will set viewWidth and viewHeight
            // to NaN in translateMatrixAfterRotate. To avoid this, call savePreviousImageValues
            // to set them equal to the current values.
            //
            if (prevMatchViewWidth == 0 || prevMatchViewHeight == 0) {
                savePreviousImageValues();
            }

            prevMatrix.getValues(m);

            //
            // Rescale Matrix after rotation
            //
            m[Matrix.MSCALE_X] = matchViewWidth / drawableWidth * normalizedScale;
            m[Matrix.MSCALE_Y] = matchViewHeight / drawableHeight * normalizedScale;

            //
            // TransX and TransY from previous matrix
            //
            float transX = m[Matrix.MTRANS_X];
            float transY = m[Matrix.MTRANS_Y];

            //
            // Width
            //
            float prevActualWidth = prevMatchViewWidth * normalizedScale;
            float actualWidth = getImageWidth();
            translateMatrixAfterRotate(Matrix.MTRANS_X, transX, prevActualWidth, actualWidth, prevViewWidth, viewWidth, drawableWidth);

            //
            // Height
            //
            float prevActualHeight = prevMatchViewHeight * normalizedScale;
            float actualHeight = getImageHeight();
            translateMatrixAfterRotate(Matrix.MTRANS_Y, transY, prevActualHeight, actualHeight, prevViewHeight, viewHeight, drawableHeight);

            //
            // Set the matrix to the adjusted scale and translate values.
            //
            matrix.setValues(m);
        }
        fixTrans();
        setImageMatrix(matrix);
    }

    /**
     * Set view dimensions based on layout params
     *
     * @param mode
     * @param size
     * @param drawableWidth
     * @return
     */
    private int setViewSize(int mode, int size, int drawableWidth) {
        int viewSize;
        switch (mode) {
            case MeasureSpec.EXACTLY:
                viewSize = size;
                break;

            case MeasureSpec.AT_MOST:
                viewSize = Math.min(drawableWidth, size);
                break;

            case MeasureSpec.UNSPECIFIED:
                viewSize = drawableWidth;
                break;

            default:
                viewSize = size;
                break;
        }
        return viewSize;
    }

    /**
     * After rotating, the matrix needs to be translated. This function finds the area of image
     * which was previously centered and adjusts translations so that is again the center, post-rotation.
     *
     * @param axis          Matrix.MTRANS_X or Matrix.MTRANS_Y
     * @param trans         the value of trans in that axis before the rotation
     * @param prevImageSize the width/height of the image before the rotation
     * @param imageSize     width/height of the image after rotation
     * @param prevViewSize  width/height of view before rotation
     * @param viewSize      width/height of view after rotation
     * @param drawableSize  width/height of drawable
     */
    private void translateMatrixAfterRotate(int axis, float trans, float prevImageSize, float imageSize, int prevViewSize, int viewSize, int drawableSize) {
        if (imageSize < viewSize) {
            //
            // The width/height of image is less than the view's width/height. Center it.
            //
            m[axis] = (viewSize - (drawableSize * m[Matrix.MSCALE_X])) * 0.5f;

        } else if (trans > 0) {
            //
            // The image is larger than the view, but was not before rotation. Center it.
            //
            m[axis] = -((imageSize - viewSize) * 0.5f);

        } else {
            //
            // Find the area of the image which was previously centered in the view. Determine its distance
            // from the left/top side of the view as a fraction of the entire image's width/height. Use that percentage
            // to calculate the trans in the new view width/height.
            //
            float percentage = (Math.abs(trans) + (0.5f * prevViewSize)) / prevImageSize;
            m[axis] = -((percentage * imageSize) - (viewSize * 0.5f));
        }
    }

    private void setState(State state) {
        this.state = state;
    }

    public boolean canScrollHorizontallyFroyo(int direction) {
        return canScrollHorizontally(direction);
    }

    @Override
    public boolean canScrollHorizontally(int direction) {
        matrix.getValues(m);
        float x = m[Matrix.MTRANS_X];

        if (getImageWidth() < viewWidth) {
            return false;

        } else if (x >= -1 && direction < 0) {
            return false;

        } else if (Math.abs(x) + viewWidth + 1 >= getImageWidth() && direction > 0) {
            return false;
        }

        return true;
    }

    /**
     * Gesture Listener detects a single click or long click and passes that on
     * to the view's listener.
     *
     * @author Ortiz
     */
    private class GestureListener extends GestureDetector.SimpleOnGestureListener {

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (doubleTapListener != null) {
                return doubleTapListener.onSingleTapConfirmed(e);
            }
            return performClick();
        }

        @Override
        public void onLongPress(MotionEvent e) {
            performLongClick();
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (fling != null) {
                //
                // If a previous fling is still active, it should be cancelled so that two flings
                // are not run simultaenously.
                //
                fling.cancelFling();
            }
            fling = new Fling((int) velocityX, (int) velocityY);
            compatPostOnAnimation(fling);
            return super.onFling(e1, e2, velocityX, velocityY);
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            boolean consumed = false;
            if (doubleTapListener != null) {
                consumed = doubleTapListener.onDoubleTap(e);
            }
            if (state == State.NONE) {
                float targetZoom = (normalizedScale == minScale) ? maxScale : minScale;
                DoubleTapZoom doubleTap = new DoubleTapZoom(targetZoom, e.getX(), e.getY(), false);
                compatPostOnAnimation(doubleTap);
                consumed = true;
            }
            return consumed;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            return doubleTapListener != null && doubleTapListener.onDoubleTapEvent(e);
        }
    }

    public interface OnTouchImageViewListener {
        public void onMove();
    }

    /**
     * Responsible for all touch events. Handles the heavy lifting of drag and also sends
     * touch events to Scale Detector and Gesture Detector.
     *
     * @author Ortiz
     */
    private class PrivateOnTouchListener implements OnTouchListener {

        //
        // Remember last point position for dragging
        //
        private PointF last = new PointF();

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            mScaleDetector.onTouchEvent(event);
            mGestureDetector.onTouchEvent(event);
            PointF curr = new PointF(event.getX(), event.getY());

            if (state == State.NONE || state == State.DRAG || state == State.FLING) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        last.set(curr);
                        if (fling != null)
                            fling.cancelFling();
                        setState(State.DRAG);
                        break;

                    case MotionEvent.ACTION_MOVE:
                        if (state == State.DRAG) {
                            float deltaX = curr.x - last.x;
                            float deltaY = curr.y - last.y;
                            float fixTransX = getFixDragTrans(deltaX, viewWidth, getImageWidth());
                            float fixTransY = getFixDragTrans(deltaY, viewHeight, getImageHeight());
                            matrix.postTranslate(fixTransX, fixTransY);
                            fixTrans();
                            last.set(curr.x, curr.y);
                        }
                        break;

                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_POINTER_UP:
                        setState(State.NONE);
                        break;
                }
            }

            setImageMatrix(matrix);

            //
            // User-defined OnTouchListener
            //
            if (userTouchListener != null) {
                userTouchListener.onTouch(v, event);
            }

            //
            // OnTouchImageViewListener is set: TouchImageView dragged by user.
            //
            if (touchImageViewListener != null) {
                touchImageViewListener.onMove();
            }

            //
            // indicate event was handled
            //
            return true;
        }
    }

    /**
     * ScaleListener detects user two finger scaling and scales image.
     *
     * @author Ortiz
     */
    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            setState(State.ZOOM);
            return true;
        }

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            scaleImage(detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY(), true);

            //
            // OnTouchImageViewListener is set: TouchImageView pinch zoomed by user.
            //
            if (touchImageViewListener != null) {
                touchImageViewListener.onMove();
            }
            return true;
        }

        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            super.onScaleEnd(detector);
            setState(State.NONE);
            boolean animateToZoomBoundary = false;
            float targetZoom = normalizedScale;
            if (normalizedScale > maxScale) {
                targetZoom = maxScale;
                animateToZoomBoundary = true;

            } else if (normalizedScale < minScale) {
                targetZoom = minScale;
                animateToZoomBoundary = true;
            }

            if (animateToZoomBoundary) {
                DoubleTapZoom doubleTap = new DoubleTapZoom(targetZoom, viewWidth / 2, viewHeight / 2, true);
                compatPostOnAnimation(doubleTap);
            }
        }
    }

    private void scaleImage(double deltaScale, float focusX, float focusY, boolean stretchImageToSuper) {

        float lowerScale, upperScale;
        if (stretchImageToSuper) {
            lowerScale = superMinScale;
            upperScale = superMaxScale;

        } else {
            lowerScale = minScale;
            upperScale = maxScale;
        }

        float origScale = normalizedScale;
        normalizedScale *= deltaScale;
        if (normalizedScale > upperScale) {
            normalizedScale = upperScale;
            deltaScale = upperScale / origScale;
        } else if (normalizedScale < lowerScale) {
            normalizedScale = lowerScale;
            deltaScale = lowerScale / origScale;
        }

        matrix.postScale((float) deltaScale, (float) deltaScale, focusX, focusY);
        fixScaleTrans();
    }

    /**
     * DoubleTapZoom calls a series of runnables which apply
     * an animated zoom in/out graphic to the image.
     *
     * @author Ortiz
     */
    private class DoubleTapZoom implements Runnable {

        private long startTime;
        private static final float ZOOM_TIME = 500;
        private float startZoom, targetZoom;
        private float bitmapX, bitmapY;
        private boolean stretchImageToSuper;
        private AccelerateDecelerateInterpolator interpolator = new AccelerateDecelerateInterpolator();
        private PointF startTouch;
        private PointF endTouch;

        DoubleTapZoom(float targetZoom, float focusX, float focusY, boolean stretchImageToSuper) {
            setState(State.ANIMATE_ZOOM);
            startTime = System.currentTimeMillis();
            this.startZoom = normalizedScale;
            this.targetZoom = targetZoom;
            this.stretchImageToSuper = stretchImageToSuper;
            PointF bitmapPoint = transformCoordTouchToBitmap(focusX, focusY, false);
            this.bitmapX = bitmapPoint.x;
            this.bitmapY = bitmapPoint.y;

            //
            // Used for translating image during scaling
            //
            startTouch = transformCoordBitmapToTouch(bitmapX, bitmapY);
            endTouch = new PointF(viewWidth / 2, viewHeight / 2);
        }

        @Override
        public void run() {
            float t = interpolate();
            double deltaScale = calculateDeltaScale(t);
            scaleImage(deltaScale, bitmapX, bitmapY, stretchImageToSuper);
            translateImageToCenterTouchPosition(t);
            fixScaleTrans();
            setImageMatrix(matrix);

            //
            // OnTouchImageViewListener is set: double tap runnable updates listener
            // with every frame.
            //
            if (touchImageViewListener != null) {
                touchImageViewListener.onMove();
            }

            if (t < 1f) {
                //
                // We haven't finished zooming
                //
                compatPostOnAnimation(this);

            } else {
                //
                // Finished zooming
                //
                setState(State.NONE);
            }
        }

        /**
         * Interpolate between where the image should start and end in order to translate
         * the image so that the point that is touched is what ends up centered at the end
         * of the zoom.
         *
         * @param t
         */
        private void translateImageToCenterTouchPosition(float t) {
            float targetX = startTouch.x + t * (endTouch.x - startTouch.x);
            float targetY = startTouch.y + t * (endTouch.y - startTouch.y);
            PointF curr = transformCoordBitmapToTouch(bitmapX, bitmapY);
            matrix.postTranslate(targetX - curr.x, targetY - curr.y);
        }

        /**
         * Use interpolator to get t
         *
         * @return
         */
        private float interpolate() {
            long currTime = System.currentTimeMillis();
            float elapsed = (currTime - startTime) / ZOOM_TIME;
            elapsed = Math.min(1f, elapsed);
            return interpolator.getInterpolation(elapsed);
        }

        /**
         * Interpolate the current targeted zoom and get the delta
         * from the current zoom.
         *
         * @param t
         * @return
         */
        private double calculateDeltaScale(float t) {
            double zoom = startZoom + t * (targetZoom - startZoom);
            return zoom / normalizedScale;
        }
    }

    /**
     * This function will transform the coordinates in the touch event to the coordinate
     * system of the drawable that the imageview contain
     *
     * @param x            x-coordinate of touch event
     * @param y            y-coordinate of touch event
     * @param clipToBitmap Touch event may occur within view, but outside image content. True, to clip return value
     *                     to the bounds of the bitmap size.
     * @return Coordinates of the point touched, in the coordinate system of the original drawable.
     */
    private PointF transformCoordTouchToBitmap(float x, float y, boolean clipToBitmap) {
        matrix.getValues(m);
        float origW = getDrawable().getIntrinsicWidth();
        float origH = getDrawable().getIntrinsicHeight();
        float transX = m[Matrix.MTRANS_X];
        float transY = m[Matrix.MTRANS_Y];
        float finalX = ((x - transX) * origW) / getImageWidth();
        float finalY = ((y - transY) * origH) / getImageHeight();

        if (clipToBitmap) {
            finalX = Math.min(Math.max(finalX, 0), origW);
            finalY = Math.min(Math.max(finalY, 0), origH);
        }

        return new PointF(finalX, finalY);
    }

    /**
     * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
     * drawable's coordinate system to the view's coordinate system.
     *
     * @param bx x-coordinate in original bitmap coordinate system
     * @param by y-coordinate in original bitmap coordinate system
     * @return Coordinates of the point in the view's coordinate system.
     */
    private PointF transformCoordBitmapToTouch(float bx, float by) {
        matrix.getValues(m);
        float origW = getDrawable().getIntrinsicWidth();
        float origH = getDrawable().getIntrinsicHeight();
        float px = bx / origW;
        float py = by / origH;
        float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
        float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
        return new PointF(finalX, finalY);
    }

    /**
     * Fling launches sequential runnables which apply
     * the fling graphic to the image. The values for the translation
     * are interpolated by the Scroller.
     *
     * @author Ortiz
     */
    private class Fling implements Runnable {

        CompatScroller scroller;
        int currX, currY;

        Fling(int velocityX, int velocityY) {
            setState(State.FLING);
            scroller = new CompatScroller(context);
            matrix.getValues(m);

            int startX = (int) m[Matrix.MTRANS_X];
            int startY = (int) m[Matrix.MTRANS_Y];
            int minX, maxX, minY, maxY;

            if (getImageWidth() > viewWidth) {
                minX = viewWidth - (int) getImageWidth();
                maxX = 0;

            } else {
                minX = maxX = startX;
            }

            if (getImageHeight() > viewHeight) {
                minY = viewHeight - (int) getImageHeight();
                maxY = 0;

            } else {
                minY = maxY = startY;
            }

            scroller.fling(startX, startY, (int) velocityX, (int) velocityY, minX,
                    maxX, minY, maxY);
            currX = startX;
            currY = startY;
        }

        public void cancelFling() {
            if (scroller != null) {
                setState(State.NONE);
                scroller.forceFinished(true);
            }
        }

        @Override
        public void run() {

            //
            // OnTouchImageViewListener is set: TouchImageView listener has been flung by user.
            // Listener runnable updated with each frame of fling animation.
            //
            if (touchImageViewListener != null) {
                touchImageViewListener.onMove();
            }

            if (scroller.isFinished()) {
                scroller = null;
                return;
            }

            if (scroller.computeScrollOffset()) {
                int newX = scroller.getCurrX();
                int newY = scroller.getCurrY();
                int transX = newX - currX;
                int transY = newY - currY;
                currX = newX;
                currY = newY;
                matrix.postTranslate(transX, transY);
                fixTrans();
                setImageMatrix(matrix);
                compatPostOnAnimation(this);
            }
        }
    }

    @TargetApi(VERSION_CODES.GINGERBREAD)
    private class CompatScroller {
        Scroller scroller;
        OverScroller overScroller;
        boolean isPreGingerbread;

        public CompatScroller(Context context) {
            if (VERSION.SDK_INT < VERSION_CODES.GINGERBREAD) {
                isPreGingerbread = true;
                scroller = new Scroller(context);

            } else {
                isPreGingerbread = false;
                overScroller = new OverScroller(context);
            }
        }

        public void fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY) {
            if (isPreGingerbread) {
                scroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY);
            } else {
                overScroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY);
            }
        }

        public void forceFinished(boolean finished) {
            if (isPreGingerbread) {
                scroller.forceFinished(finished);
            } else {
                overScroller.forceFinished(finished);
            }
        }

        public boolean isFinished() {
            if (isPreGingerbread) {
                return scroller.isFinished();
            } else {
                return overScroller.isFinished();
            }
        }

        public boolean computeScrollOffset() {
            if (isPreGingerbread) {
                return scroller.computeScrollOffset();
            } else {
                overScroller.computeScrollOffset();
                return overScroller.computeScrollOffset();
            }
        }

        public int getCurrX() {
            if (isPreGingerbread) {
                return scroller.getCurrX();
            } else {
                return overScroller.getCurrX();
            }
        }

        public int getCurrY() {
            if (isPreGingerbread) {
                return scroller.getCurrY();
            } else {
                return overScroller.getCurrY();
            }
        }
    }

    @TargetApi(VERSION_CODES.JELLY_BEAN)
    private void compatPostOnAnimation(Runnable runnable) {
        if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
            postOnAnimation(runnable);

        } else {
            postDelayed(runnable, 1000 / 60);
        }
    }

    private class ZoomVariables {
        public float scale;
        public float focusX;
        public float focusY;
        public ScaleType scaleType;

        public ZoomVariables(float scale, float focusX, float focusY, ScaleType scaleType) {
            this.scale = scale;
            this.focusX = focusX;
            this.focusY = focusY;
            this.scaleType = scaleType;
        }
    }

    private void printMatrixInfo() {
        float[] n = new float[9];
        matrix.getValues(n);
        Log.d(DEBUG, "Scale: " + n[Matrix.MSCALE_X] + " TransX: " + n[Matrix.MTRANS_X] + " TransY: " + n[Matrix.MTRANS_Y]);
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/ui/weiget/URLSpanNoUnderline.groovy
================================================
package zhou.gank.io.ui.weiget

import android.content.Intent
import android.net.Uri
import android.os.Parcel
import android.support.annotation.NonNull
import android.text.SpannableStringBuilder
import android.text.TextPaint
import android.text.style.URLSpan
import android.view.View
import android.widget.TextView
import groovy.transform.CompileStatic
import zhou.gank.io.App
import zhou.gank.io.R
import zhou.gank.io.comment.Config
import zhou.gank.io.ui.activity.WebActivity
import zhou.gank.io.util.LogKit;

@CompileStatic
class URLSpanNoUnderline extends URLSpan {
    URLSpanNoUnderline(String url) {
        super(url)
    }

    URLSpanNoUnderline(Parcel src) {
        super(src)
    }

    @Override
    public void updateDrawState(@NonNull TextPaint ds) {
        super.updateDrawState(ds);
        ds.setUnderlineText(false);
    }

    @Override
    void onClick(View widget) {
        def open = Config.getBoolean(widget.getResources().getString(R.string.key_open), Config.Configurable.HANDLE_BY_ME);
        if (open) {
            Intent intent = new Intent(widget.getContext(), WebActivity.class)
            intent.putExtra(Config.Static.URL, getURL())
            widget.getContext().startActivity(intent)
        } else {
            super.onClick(widget)
        }
    }
}

================================================
FILE: app/src/main/groovy/zhou/gank/io/util/FileKit.java
================================================
package zhou.gank.io.util;

import android.graphics.Bitmap;
import android.util.Log;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.text.DecimalFormat;

/**
 * Created by 州 on 2015/7/4 0004.
 * 文件操作相关工具类
 */
public class FileKit {

    public static DecimalFormat decimalFormat = new DecimalFormat(".00");

    /**
     * 判断文件是否存在
     *
     * @param path 文件的全路径
     * @return 文件是否存在
     */
    @SuppressWarnings("unused")
    public static boolean isFileExists(String path) {
        File file = new File(path);
        return file.exists();
    }

    @SuppressWarnings("unused")
    public static boolean isFileExists(File parent, String name) {
        File file = new File(parent, name);
        return file.exists();
    }

    /**
     * 获取文件的后缀名
     *
     * @param path 文件全路径
     * @return 后缀名
     */
    @SuppressWarnings("unused")
    public static String getFileExtension(String path) {
        return path == null ? null : path.substring(path.lastIndexOf(".") + 1);
    }

    /**
     * 去掉路径的后缀名
     *
     * @param path 文件全路径
     * @return 去后缀名后的文件名
     */
    @SuppressWarnings("unused")
    public static String getPathWithoutExtension(String path) {
        return path == null ? null : path.substring(0, path.lastIndexOf("."));
    }

    /**
     * 将对象写入指定路径的文件中
     *
     * @param path 文件路径
     * @param obj  需要被写入的对象
     */
    @SuppressWarnings("unused")
    public static void writeObject(String path, Object obj) {
        File file = new File(path);
        writeObject(file, obj);
    }

    /**
     * 写入对象到文件中
     *
     * @param file 文件对象
     * @param obj  需要写入文件的对象
     */
    @SuppressWarnings("unused")
    public static void writeObject(File file, Object obj) {
        if (null == file || obj == null) {
            return;
        }
        FileOutputStream fileOutputStream = null;
        ObjectOutputStream objectOutputStream = null;

        try {
            fileOutputStream = new FileOutputStream(file);
            objectOutputStream = new ObjectOutputStream(fileOutputStream);

            objectOutputStream.writeObject(obj);
            objectOutputStream.flush();
        } catch (IOException e) {
            Log.d("writeObject", e.getMessage());
        } finally {
            try {
                if (objectOutputStream != null) {
                    objectOutputStream.close();
                }
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
            } catch (IOException e) {
                Log.d("writeObject", e.getMessage());
            }
        }
    }

    /**
     * 从指定路径的文件中读取对象
     *
     * @param path 文件路径
     * @return 读取到的对象
     */
    @SuppressWarnings("unused")
    public static Object readObject(String path) {
        File file = new File(path);
        return readObject(file);
    }

    /**
     * 从文件中读取对象
     *
     * @param file 文件对象
     * @return 读取到的对象
     */
    public static Object readObject(File file) {
        Object obj = null;
        if (file != null && file.exists()) {
            FileInputStream fileInputStream = null;
            ObjectInputStream objectInputStream = null;

            try {
                fileInputStream = new FileInputStream(file);
                objectInputStream = new ObjectInputStream(fileInputStream);

                obj = objectInputStream.readObject();
            } catch (IOException | ClassNotFoundException e) {
                Log.d("readObject", e.getMessage());
            } finally {
                try {
                    if (objectInputStream != null) {
                        objectInputStream.close();
                    }
                    if (fileInputStream != null) {
                        fileInputStream.close();
                    }
                } catch (IOException e) {
                    Log.d("readObject", e.getMessage());
                }

            }
        }
        return obj;
    }

    public static void writeString(File file, String content) {
        FileOutputStream fileOutputStream = null;
        OutputStreamWriter outputStreamWriter = null;
        BufferedWriter bufferedWriter = null;

        try {
            fileOutputStream = new FileOutputStream(file);
            outputStreamWriter = new OutputStreamWriter(fileOutputStream);
            bufferedWriter = new BufferedWriter(outputStreamWriter);

            bufferedWriter.write(content);

        } catch (IOException e) {
            Log.d("writeString", "error", e);
        } finally {
            try {
                if (bufferedWriter != null) {
                    bufferedWriter.close();
                }
                if (outputStreamWriter != null) {
                    outputStreamWriter.close();
                }
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
            } catch (IOException e) {
                Log.d("writeString", "error final", e);
            }
        }
    }

    public static String readString(File file) {
        FileInputStream fileInputStream = null;
        InputStreamReader inputStreamReader = null;
        BufferedReader bufferedReader = null;

        String content = null;

        try {
            fileInputStream = new FileInputStream(file);
            inputStreamReader = new InputStreamReader(fileInputStream);
            bufferedReader = new BufferedReader(inputStreamReader);

            String line;
            StringBuilder sb = new StringBuilder();
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line).append("\n");
            }
            sb.deleteCharAt(sb.length() - 1);
            content = sb.toString();
        } catch (FileNotFoundException e) {
            Log.d("readString", "error", e);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
                if (inputStreamReader != null) {
                    inputStreamReader.close();
                }
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
            } catch (IOException e) {
                Log.d("readString", "error final", e);
            }
        }
        return content;
    }

    /**
     * 格式化文件大小以字符串输出
     *
     * @param size 大小
     * @return B、KB、MB类型的字符串
     */
    @SuppressWarnings("unused")
    public static String formatSize(int size) {
        if (size < 1024 * 0.6) {
            return size + "B";
        } else if (size < 1024 * 1024 * 0.6) {
            return decimalFormat.format((float) size / 1024) + "KB";
        } else {
            return decimalFormat.format((float) size / (1024 * 1024)) + "MB";
        }
    }

    public static void saveBitmapFile(Bitmap bitmap, File file) {
        FileOutputStream fileOutputStream = null;
        BufferedOutputStream bufferedOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(file);
            bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bufferedOutputStream);
            bufferedOutputStream.flush();
            bufferedOutputStream.close();
        } catch (IOException e) {
            LogKit.d("saveBitmapFile", "error", e);
        } finally {
            try {
                if (bufferedOutputStream != null) {
                    bufferedOutputStream.close();
                }
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
            } catch (IOException e) {
                LogKit.d("saveBitmapFile", "error", e);
            }
        }
    }

    public static String getFileRealName(String path) {
        return path.substring(path.lastIndexOf("/") + 1);
    }

}


================================================
FILE: app/src/main/groovy/zhou/gank/io/util/HashKit.java
================================================
package zhou.gank.io.util;

import java.security.MessageDigest;

/**
 * Created by zzhoujay on 2015/7/31 0031.
 * 加密相关工具类
 */
public class HashKit {

    private static java.security.SecureRandom random = new java.security.SecureRandom();

    public static String md5(String srcStr){
        return hash("MD5", srcStr);
    }

    public static String sha1(String srcStr){
        return hash("SHA-1", srcStr);
    }

    public static String sha256(String srcStr){
        return hash("SHA-256", srcStr);
    }

    public static String sha384(String srcStr){
        return hash("SHA-384", srcStr);
    }

    public static String sha512(String srcStr){
        return hash("SHA-512", srcStr);
    }

    public static String hash(String algorithm, String srcStr) {
        try {
            StringBuilder result = new StringBuilder();
            MessageDigest md = MessageDigest.getInstance(algorithm);
            byte[] bytes = md.digest(srcStr.getBytes("utf-8"));
            for (byte b : bytes) {
                String hex = Integer.toHexString(b&0xFF);
                if (hex.length() == 1)
                    result.append("0");
                result.append(hex);
            }
            return result.toString();
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private static String toHex(byte[] bytes) {
        StringBuilder result = new StringBuilder();
        for (byte b : bytes) {
            String hex = Integer.toHexString(b&0xFF);
            if (hex.length() == 1)
                result.append("0");
            result.append(hex);
        }
        return result.toString();
    }

    /**
     * md5 128bit 16bytes
     * sha1 160bit 20bytes
     * sha256 256bit 32bytes
     * sha384 384bit 48bites
     * sha512 512bit 64bites
     */
    public static String generateSalt(int numberOfBytes) {
        byte[] salt = new byte[numberOfBytes];
        random.nextBytes(salt);
        return toHex(salt);
    }
}


================================================
FILE: app/src/main/groovy/zhou/gank/io/util/JsonKit.groovy
================================================
package zhou.gank.io.util

import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.google.gson.reflect.TypeToken
import groovy.transform.CompileStatic
import zhou.gank.io.model.Gank
import zhou.gank.io.model.GankDaily
import zhou.gank.io.model.ResultDaily

@CompileStatic
class JsonKit {

    public static ResultDaily generate(String json, Gson gson) {
        JsonParser parser = new JsonParser();
        JsonElement element = parser.parse(json);
        JsonObject root = element.getAsJsonObject();
        JsonArray category = root.getAsJsonArray("category");
        Iterator<JsonElement> iterator = category.iterator();
        JsonObject results = root.getAsJsonObject("results");
        boolean error = root.get("error").getAsBoolean();
        ArrayList<String> types = new ArrayList<>(category.size());
        ArrayList<List<Gank>> ghs = new ArrayList<>(category.size());
        while (iterator.hasNext()) {
            JsonElement type = iterator.next();
            String t = type.getAsString();
            types.add(t);
            String e = results.get(t).toString();
            ghs.add(gson.fromJson(e, new TypeToken<List<Gank>>() {
            }.getType()) as List<Gank>);
        }

        ghs.sort { a, b ->
            def aa = a as List<Gank>
            def bb = b as List<Gank>
            return aa.get(0).type.compareTo(bb.get(0).type)
        }
        types.sort()

        return new ResultDaily(error, new GankDaily(types, ghs));
    }

    public static
    final String test = "{\"error\":false,\"results\":{\"iOS\":[{\"who\":\"CallMeWhy\",\"publishedAt\":\"2015-08-07T03:57:48.070Z\",\"desc\":\"LLVM 简介\",\"type\":\"iOS\",\"url\":\"http://adriansampson.net/blog/llvm.html\",\"used\":true,\"objectId\":\"55c40ac360b2c9d32a67ca25\",\"createdAt\":\"2015-08-07T01:32:51.588Z\",\"updatedAt\":\"2015-08-15T03:15:54.384Z\"},{\"who\":\"鲍永章\",\"publishedAt\":\"2015-08-07T03:57:47.242Z\",\"desc\":\"基于TextKit的UILabel,支持超链接和自定义表达式。\",\"type\":\"iOS\",\"url\":\"https://github.com/molon/MLLabel\",\"used\":true,\"objectId\":\"55c372fe60b2f809e41eb388\",\"createdAt\":\"2015-08-06T14:45:18.733Z\",\"updatedAt\":\"2015-08-15T03:15:54.536Z\"},{\"who\":\"CallMeWhy\",\"publishedAt\":\"2015-08-07T03:57:48.083Z\",\"desc\":\"Swift 和 C 函数\",\"type\":\"iOS\",\"url\":\"http://chris.eidhof.nl/posts/swift-c-interop.html\",\"used\":true,\"objectId\":\"55c40aea00b025867b19c9af\",\"createdAt\":\"2015-08-07T01:33:30.871Z\",\"updatedAt\":\"2015-08-15T03:15:54.408Z\"},{\"who\":\"CallMeWhy\",\"publishedAt\":\"2015-08-07T03:57:48.174Z\",\"desc\":\"Arrays Linked Lists 和性能比较\",\"type\":\"iOS\",\"url\":\"http://airspeedvelocity.net/2015/08/03/arrays-linked-lists-and-performance/\",\"used\":true,\"objectId\":\"55c40b0800b0fac2c2809acc\",\"createdAt\":\"2015-08-07T01:34:00.984Z\",\"updatedAt\":\"2015-08-15T03:15:55.105Z\"}],\"Android\":[{\"who\":\"mthli\",\"publishedAt\":\"2015-08-07T03:57:48.045Z\",\"desc\":\"类似Link Bubble的悬浮式操作设计\",\"type\":\"Android\",\"url\":\"https://github.com/recruit-lifestyle/FloatingView\",\"used\":true,\"objectId\":\"55c309a800b00045333db517\",\"createdAt\":\"2015-08-06T07:15:52.065Z\",\"updatedAt\":\"2015-08-15T03:15:55.098Z\"},{\"who\":\"lxxself\",\"publishedAt\":\"2015-08-07T03:57:47.317Z\",\"desc\":\"Android开发中,有哪些让你觉得相见恨晚的方法、类或接口?\",\"type\":\"Android\",\"url\":\"http://www.zhihu.com/question/33636939\",\"used\":true,\"objectId\":\"55c40ad340ac7d0a9507b324\",\"createdAt\":\"2015-08-07T01:33:07.815Z\",\"updatedAt\":\"2015-08-15T03:15:54.407Z\"},{\"who\":\"鲍永章\",\"publishedAt\":\"2015-08-07T03:57:48.076Z\",\"desc\":\"使用注解来处理Activity的状态恢复\",\"type\":\"Android\",\"url\":\"https://github.com/tom91136/Akatsuki\",\"used\":true,\"objectId\":\"55c3769660b2750766971ce6\",\"createdAt\":\"2015-08-06T15:00:38.350Z\",\"updatedAt\":\"2015-08-15T03:15:54.866Z\"},{\"who\":\"有时放纵\",\"publishedAt\":\"2015-08-07T03:57:48.142Z\",\"desc\":\"Android Lollipop联系人之PinnedListView简单使用\",\"type\":\"Android\",\"url\":\"https://git.oschina.net/way/PinnedHeaderListView\",\"used\":true,\"objectId\":\"55c415c060b2d140ca882eac\",\"createdAt\":\"2015-08-07T02:19:44.342Z\",\"updatedAt\":\"2015-08-15T03:15:55.020Z\"},{\"who\":\"鲍永章\",\"publishedAt\":\"2015-08-07T03:57:48.073Z\",\"desc\":\"图片可以自动滚动的ImageView,可以实现视差效果。\",\"type\":\"Android\",\"url\":\"https://github.com/Q42/AndroidScrollingImageView\",\"used\":true,\"objectId\":\"55c3761400b00045334480d2\",\"createdAt\":\"2015-08-06T14:58:28.171Z\",\"updatedAt\":\"2015-08-15T03:15:55.123Z\"}],\"瞎推荐\":[{\"who\":\"lxxself\",\"publishedAt\":\"2015-08-07T03:57:48.084Z\",\"desc\":\"程序员的电台FmM,这个页面chrome插件有问题啊哭,我写了回删除不了啊\",\"type\":\"瞎推荐\",\"url\":\"https://cmd.fm/\",\"used\":true,\"objectId\":\"55c40f5e00b00045334934b4\",\"createdAt\":\"2015-08-07T01:52:30.267Z\",\"updatedAt\":\"2015-08-15T03:15:54.383Z\"}],\"拓展资源\":[{\"who\":\"lxxself\",\"publishedAt\":\"2015-08-07T03:57:48.081Z\",\"desc\":\"Display GitHub code in tree format\",\"type\":\"拓展资源\",\"url\":\"https://github.com/buunguyen/octotree\",\"used\":true,\"objectId\":\"55c40b8600b08484a7f3a032\",\"createdAt\":\"2015-08-07T01:36:06.932Z\",\"updatedAt\":\"2015-08-15T03:15:54.382Z\"}],\"福利\":[{\"who\":\"张涵宇\",\"publishedAt\":\"2015-08-07T03:57:47.310Z\",\"desc\":\"8.7——(1)\",\"type\":\"福利\",\"url\":\"http://ww2.sinaimg.cn/large/7a8aed7bgw1eutscfcqtcj20dw0i0q4l.jpg\",\"used\":true,\"objectId\":\"55c4080240ac7d0a9507905e\",\"createdAt\":\"2015-08-07T01:21:06.112Z\",\"updatedAt\":\"2015-08-15T03:15:54.765Z\"},{\"who\":\"张涵宇\",\"publishedAt\":\"2015-08-07T03:57:47.229Z\",\"desc\":\"8.7——(2)\",\"type\":\"福利\",\"url\":\"http://ww2.sinaimg.cn/large/7a8aed7bgw1eutsd0pgiwj20go0p0djn.jpg\",\"used\":true,\"objectId\":\"55c4081d60b2c9d32a67a92e\",\"createdAt\":\"2015-08-07T01:21:33.518Z\",\"updatedAt\":\"2015-08-15T03:15:54.843Z\"}],\"休息视频\":[{\"who\":\"lxxself\",\"publishedAt\":\"2015-08-07T03:57:48.104Z\",\"desc\":\"听到就心情大好的歌,简直妖魔哈哈哈哈哈,原地址\\nhttp://v.youku.com/v_show/id_XMTQxODA5NDM2.html\",\"type\":\"休息视频\",\"url\":\"http://www.zhihu.com/question/21778055/answer/19905413?utm_source=weibo&utm_medium=weibo_share&utm_content=share_answer&utm_campaign=share_button\",\"used\":true,\"objectId\":\"55c35bc960b2750766954ec3\",\"createdAt\":\"2015-08-06T13:06:17.211Z\",\"updatedAt\":\"2015-08-15T03:15:54.872Z\"}]},\"category\":[\"iOS\",\"Android\",\"瞎推荐\",\"拓展资源\",\"福利\",\"休息视频\"]}";

}

================================================
FILE: app/src/main/groovy/zhou/gank/io/util/LogKit.java
================================================
package zhou.gank.io.util;

import android.util.Log;

/**
 * Created by zzhoujay on 2015/8/22 0022.
 * LogKit 可以设置日志级别
 */
public class LogKit {

    /**
     * Priority constant for the println method; use Log.v.
     */
    public static final int VERBOSE = 2;

    /**
     * Priority constant for the println method; use Log.d.
     */
    public static final int DEBUG = 3;

    /**
     * Priority constant for the println method; use Log.i.
     */
    public static final int INFO = 4;

    /**
     * Priority constant for the println method; use Log.w.
     */
    public static final int WARN = 5;

    /**
     * Priority constant for the println method; use Log.e.
     */
    public static final int ERROR = 6;

    /**
     * Priority constant for the println method.
     */
    public static final int ASSERT = 7;

    public static int level = VERBOSE;

    public static void v(String tag, String msg) {
        if (level <= VERBOSE) {
            Log.v(tag, msg);
        }
    }

    public static void v(String tag, String msg, Throwable e) {
        if (level <= VERBOSE) {
            Log.v(tag, msg, e);
        }
    }

    public static void v(String tag, Object msg) {
        v(tag, msg.toString());
    }

    public static void d(String tag, String msg) {
        if (level <= DEBUG) {
            Log.d(tag, msg);
        }
    }

    public static void d(String tag, String msg, Throwable e) {
        if (level <= DEBUG) {
            Log.d(tag, msg, e);
        }
    }

    public static void d(String tag, Object msg) {
        d(tag, msg.toString());
    }

    public static void i(String tag, String msg) {
        if (level <= INFO) {
            Log.i(tag, msg);
        }
    }

    public static void i(String tag, String msg, Throwable e) {
        if (level <= INFO) {
            Log.i(tag, msg, e);
        }
    }

    public static void i(String tag, Object msg) {
        i(tag, msg.toString());
    }

    public static void w(String tag, String msg) {
        if (level <= WARN) {
            Log.w(tag, msg);
        }
    }

    public static void w(String tag, String msg, Throwable e) {
        if (level <= WARN) {
            Log.w(tag, msg, e);
        }
    }

    public static void w(String tag, Throwable e) {
        if (level <= WARN) {
            Log.w(tag, e);
        }
    }

    public static void w(String tag, Object msg) {
        w(tag, msg.toString());
    }

    public static void e(String tag, String msg) {
        if (level <= ERROR) {
            Log.e(tag, msg);
        }
    }

    public static void e(String tag, String msg, Throwable e) {
        if (level <= ERROR) {
            Log.e(tag, msg, e);
        }
    }

    public static void e(String tag, Object msg) {
        e(tag, msg.toString());
    }
}


================================================
FILE: app/src/main/groovy/zhou/gank/io/util/NetworkKit.groovy
================================================
Download .txt
gitextract_8uf00tm3/

├── .gitignore
├── LICENSE
├── README.md
├── app/
│   ├── .gitignore
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src/
│       ├── androidTest/
│       │   └── java/
│       │       └── zhou/
│       │           └── gank/
│       │               └── io/
│       │                   └── ApplicationTest.java
│       └── main/
│           ├── AndroidManifest.xml
│           ├── groovy/
│           │   └── zhou/
│           │       └── gank/
│           │           └── io/
│           │               ├── App.groovy
│           │               ├── MainActivity.groovy
│           │               ├── comment/
│           │               │   └── Config.groovy
│           │               ├── data/
│           │               │   ├── CollectProvider.groovy
│           │               │   ├── DataManager.groovy
│           │               │   ├── DataProvider.groovy
│           │               │   ├── RandomProvider.groovy
│           │               │   ├── TimeProvider.groovy
│           │               │   └── TypeProvider.groovy
│           │               ├── database/
│           │               │   └── DatabaseManager.groovy
│           │               ├── model/
│           │               │   ├── BaseResult.groovy
│           │               │   ├── Bookmark.groovy
│           │               │   ├── Gank.groovy
│           │               │   ├── GankDaily.groovy
│           │               │   ├── Result.groovy
│           │               │   └── ResultDaily.groovy
│           │               ├── net/
│           │               │   └── NetworkManager.groovy
│           │               ├── ui/
│           │               │   ├── activity/
│           │               │   │   ├── CollectActivity.groovy
│           │               │   │   ├── DailyActivity.groovy
│           │               │   │   ├── HomeActivity.groovy
│           │               │   │   ├── ImageGalleryActivity.groovy
│           │               │   │   ├── SettingActivity.groovy
│           │               │   │   ├── TabActivity.groovy
│           │               │   │   ├── ToolbarActivity.groovy
│           │               │   │   └── WebActivity.groovy
│           │               │   ├── adapter/
│           │               │   │   ├── BaseAdapter.groovy
│           │               │   │   ├── DailyAdapter.groovy
│           │               │   │   ├── GankAdapter.groovy
│           │               │   │   ├── ImageAdapter.groovy
│           │               │   │   └── ImageGalleryAdapter.groovy
│           │               │   ├── dialog/
│           │               │   │   └── InfoDialog.groovy
│           │               │   ├── fragment/
│           │               │   │   ├── AdvanceFragment.groovy
│           │               │   │   ├── BaseFragment.groovy
│           │               │   │   ├── DailyFragment.groovy
│           │               │   │   ├── GankFragment.groovy
│           │               │   │   ├── ImageFragment.groovy
│           │               │   │   ├── ImageGalleryFragment.groovy
│           │               │   │   ├── ImagePageFragment.groovy
│           │               │   │   ├── SettingFragment.groovy
│           │               │   │   └── WebFragment.groovy
│           │               │   └── weiget/
│           │               │       ├── SwipeToRefreshLayout.groovy
│           │               │       ├── TouchImageView.java
│           │               │       └── URLSpanNoUnderline.groovy
│           │               └── util/
│           │                   ├── FileKit.java
│           │                   ├── HashKit.java
│           │                   ├── JsonKit.groovy
│           │                   ├── LogKit.java
│           │                   ├── NetworkKit.groovy
│           │                   ├── Notifier.groovy
│           │                   ├── NumKit.groovy
│           │                   ├── Pageable.groovy
│           │                   ├── TextKit.groovy
│           │                   └── TimeKit.groovy
│           └── res/
│               ├── drawable/
│               │   ├── ic_bookmark_48px.xml
│               │   ├── ic_cloud_off_48px.xml
│               │   ├── ic_cloud_queue_48px.xml
│               │   ├── ic_dashboard_48px.xml
│               │   ├── ic_event_48px.xml
│               │   ├── ic_extension_48px.xml
│               │   ├── ic_favorite_white_48px.xml
│               │   ├── ic_info_48px.xml
│               │   ├── ic_insert_emoticon_48px.xml
│               │   ├── ic_menu_white_48px.xml
│               │   ├── ic_refresh_48px.xml
│               │   ├── ic_settings_black_48px.xml
│               │   └── ic_view_module_48px.xml
│               ├── layout/
│               │   ├── activity_compat.xml
│               │   ├── activity_home.xml
│               │   ├── activity_main.xml
│               │   ├── activity_tab.xml
│               │   ├── activity_toolbar.xml
│               │   ├── dialog_text.xml
│               │   ├── fragment_daily.xml
│               │   ├── fragment_image_page.xml
│               │   ├── fragment_recyler_view.xml
│               │   ├── fragment_viewpager.xml
│               │   ├── fragment_web.xml
│               │   ├── item_daily.xml
│               │   ├── item_gank.xml
│               │   ├── item_image.xml
│               │   ├── layout_gallery.xml
│               │   ├── layout_more.xml
│               │   └── nav_header.xml
│               ├── menu/
│               │   ├── drawer_view.xml
│               │   ├── menu_pop.xml
│               │   ├── menu_pop_add.xml
│               │   ├── menu_pop_remove.xml
│               │   └── menu_web.xml
│               ├── values/
│               │   ├── colors.xml
│               │   ├── dimens.xml
│               │   ├── strings.xml
│               │   └── styles.xml
│               ├── values-en/
│               │   └── strings.xml
│               ├── values-v21/
│               │   └── styles.xml
│               └── xml/
│                   └── setting.xml
├── build.gradle
├── gradle/
│   └── wrapper/
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
Download .txt
SYMBOL INDEX (128 symbols across 5 files)

FILE: app/src/androidTest/java/zhou/gank/io/ApplicationTest.java
  class ApplicationTest (line 9) | public class ApplicationTest extends ApplicationTestCase<Application> {
    method ApplicationTest (line 10) | public ApplicationTest() {

FILE: app/src/main/groovy/zhou/gank/io/ui/weiget/TouchImageView.java
  class TouchImageView (line 42) | public class TouchImageView extends ImageView {
    type State (line 67) | private enum State {NONE, DRAG, ZOOM, FLING, ANIMATE_ZOOM}
    method TouchImageView (line 103) | public TouchImageView(Context context) {
    method TouchImageView (line 108) | public TouchImageView(Context context, AttributeSet attrs) {
    method TouchImageView (line 113) | public TouchImageView(Context context, AttributeSet attrs, int defStyl...
    method sharedConstructing (line 118) | private void sharedConstructing(Context context) {
    method setOnTouchListener (line 141) | @Override
    method setOnTouchImageViewListener (line 146) | public void setOnTouchImageViewListener(OnTouchImageViewListener l) {
    method setOnDoubleTapListener (line 150) | public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener...
    method setImageResource (line 154) | @Override
    method setImageBitmap (line 161) | @Override
    method setImageDrawable (line 168) | @Override
    method setImageURI (line 175) | @Override
    method setScaleType (line 182) | @Override
    method getScaleType (line 202) | @Override
    method isZoomed (line 212) | public boolean isZoomed() {
    method getZoomedRect (line 221) | public RectF getZoomedRect() {
    method savePreviousImageValues (line 237) | private void savePreviousImageValues() {
    method onSaveInstanceState (line 248) | @Override
    method onRestoreInstanceState (line 263) | @Override
    method onDraw (line 282) | @Override
    method onConfigurationChanged (line 293) | @Override
    method getMaxZoom (line 304) | public float getMaxZoom() {
    method setMaxZoom (line 313) | public void setMaxZoom(float max) {
    method getMinZoom (line 323) | public float getMinZoom() {
    method getCurrentZoom (line 333) | public float getCurrentZoom() {
    method setMinZoom (line 342) | public void setMinZoom(float min) {
    method resetZoom (line 350) | public void resetZoom() {
    method setZoom (line 360) | public void setZoom(float scale) {
    method setZoom (line 374) | public void setZoom(float scale, float focusX, float focusY) {
    method setZoom (line 389) | public void setZoom(float scale, float focusX, float focusY, ScaleType...
    method setZoom (line 419) | public void setZoom(TouchImageView img) {
    method getScrollPosition (line 432) | public PointF getScrollPosition() {
    method setScrollPosition (line 453) | public void setScrollPosition(float focusX, float focusY) {
    method fixTrans (line 461) | private void fixTrans() {
    method fixScaleTrans (line 481) | private void fixScaleTrans() {
    method getFixTrans (line 494) | private float getFixTrans(float trans, float viewSize, float contentSi...
    method getFixDragTrans (line 513) | private float getFixDragTrans(float delta, float viewSize, float conte...
    method getImageWidth (line 520) | private float getImageWidth() {
    method getImageHeight (line 524) | private float getImageHeight() {
    method onMeasure (line 528) | @Override
    method fitImageToView (line 561) | private void fitImageToView() {
    method setViewSize (line 676) | private int setViewSize(int mode, int size, int drawableWidth) {
    method translateMatrixAfterRotate (line 710) | private void translateMatrixAfterRotate(int axis, float trans, float p...
    method setState (line 734) | private void setState(State state) {
    method canScrollHorizontallyFroyo (line 738) | public boolean canScrollHorizontallyFroyo(int direction) {
    method canScrollHorizontally (line 742) | @Override
    class GestureListener (line 766) | private class GestureListener extends GestureDetector.SimpleOnGestureL...
      method onSingleTapConfirmed (line 768) | @Override
      method onLongPress (line 776) | @Override
      method onFling (line 781) | @Override
      method onDoubleTap (line 795) | @Override
      method onDoubleTapEvent (line 810) | @Override
    type OnTouchImageViewListener (line 816) | public interface OnTouchImageViewListener {
      method onMove (line 817) | public void onMove();
    class PrivateOnTouchListener (line 826) | private class PrivateOnTouchListener implements OnTouchListener {
      method onTouch (line 833) | @Override
    class ScaleListener (line 895) | private class ScaleListener extends ScaleGestureDetector.SimpleOnScale...
      method onScaleBegin (line 896) | @Override
      method onScale (line 902) | @Override
      method onScaleEnd (line 915) | @Override
    method scaleImage (line 937) | private void scaleImage(double deltaScale, float focusX, float focusY,...
    class DoubleTapZoom (line 969) | private class DoubleTapZoom implements Runnable {
      method DoubleTapZoom (line 980) | DoubleTapZoom(float targetZoom, float focusX, float focusY, boolean ...
      method run (line 997) | @Override
      method translateImageToCenterTouchPosition (line 1035) | private void translateImageToCenterTouchPosition(float t) {
      method interpolate (line 1047) | private float interpolate() {
      method calculateDeltaScale (line 1061) | private double calculateDeltaScale(float t) {
    method transformCoordTouchToBitmap (line 1077) | private PointF transformCoordTouchToBitmap(float x, float y, boolean c...
    method transformCoordBitmapToTouch (line 1102) | private PointF transformCoordBitmapToTouch(float bx, float by) {
    class Fling (line 1120) | private class Fling implements Runnable {
      method Fling (line 1125) | Fling(int velocityX, int velocityY) {
      method cancelFling (line 1156) | public void cancelFling() {
      method run (line 1163) | @Override
    class CompatScroller (line 1194) | @TargetApi(VERSION_CODES.GINGERBREAD)
      method CompatScroller (line 1200) | public CompatScroller(Context context) {
      method fling (line 1211) | public void fling(int startX, int startY, int velocityX, int velocit...
      method forceFinished (line 1219) | public void forceFinished(boolean finished) {
      method isFinished (line 1227) | public boolean isFinished() {
      method computeScrollOffset (line 1235) | public boolean computeScrollOffset() {
      method getCurrX (line 1244) | public int getCurrX() {
      method getCurrY (line 1252) | public int getCurrY() {
    method compatPostOnAnimation (line 1261) | @TargetApi(VERSION_CODES.JELLY_BEAN)
    class ZoomVariables (line 1271) | private class ZoomVariables {
      method ZoomVariables (line 1277) | public ZoomVariables(float scale, float focusX, float focusY, ScaleT...
    method printMatrixInfo (line 1285) | private void printMatrixInfo() {

FILE: app/src/main/groovy/zhou/gank/io/util/FileKit.java
  class FileKit (line 24) | public class FileKit {
    method isFileExists (line 34) | @SuppressWarnings("unused")
    method isFileExists (line 40) | @SuppressWarnings("unused")
    method getFileExtension (line 52) | @SuppressWarnings("unused")
    method getPathWithoutExtension (line 63) | @SuppressWarnings("unused")
    method writeObject (line 74) | @SuppressWarnings("unused")
    method writeObject (line 86) | @SuppressWarnings("unused")
    method readObject (line 122) | @SuppressWarnings("unused")
    method readObject (line 134) | public static Object readObject(File file) {
    method writeString (line 164) | public static void writeString(File file, String content) {
    method readString (line 195) | public static String readString(File file) {
    method formatSize (line 242) | @SuppressWarnings("unused")
    method saveBitmapFile (line 253) | public static void saveBitmapFile(Bitmap bitmap, File file) {
    method getFileRealName (line 278) | public static String getFileRealName(String path) {

FILE: app/src/main/groovy/zhou/gank/io/util/HashKit.java
  class HashKit (line 9) | public class HashKit {
    method md5 (line 13) | public static String md5(String srcStr){
    method sha1 (line 17) | public static String sha1(String srcStr){
    method sha256 (line 21) | public static String sha256(String srcStr){
    method sha384 (line 25) | public static String sha384(String srcStr){
    method sha512 (line 29) | public static String sha512(String srcStr){
    method hash (line 33) | public static String hash(String algorithm, String srcStr) {
    method toHex (line 51) | private static String toHex(byte[] bytes) {
    method generateSalt (line 69) | public static String generateSalt(int numberOfBytes) {

FILE: app/src/main/groovy/zhou/gank/io/util/LogKit.java
  class LogKit (line 9) | public class LogKit {
    method v (line 43) | public static void v(String tag, String msg) {
    method v (line 49) | public static void v(String tag, String msg, Throwable e) {
    method v (line 55) | public static void v(String tag, Object msg) {
    method d (line 59) | public static void d(String tag, String msg) {
    method d (line 65) | public static void d(String tag, String msg, Throwable e) {
    method d (line 71) | public static void d(String tag, Object msg) {
    method i (line 75) | public static void i(String tag, String msg) {
    method i (line 81) | public static void i(String tag, String msg, Throwable e) {
    method i (line 87) | public static void i(String tag, Object msg) {
    method w (line 91) | public static void w(String tag, String msg) {
    method w (line 97) | public static void w(String tag, String msg, Throwable e) {
    method w (line 103) | public static void w(String tag, Throwable e) {
    method w (line 109) | public static void w(String tag, Object msg) {
    method e (line 113) | public static void e(String tag, String msg) {
    method e (line 119) | public static void e(String tag, String msg, Throwable e) {
    method e (line 125) | public static void e(String tag, Object msg) {
Condensed preview — 110 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (298K chars).
[
  {
    "path": ".gitignore",
    "chars": 346,
    "preview": ".gradle\n/local.properties\n.DS_Store\n/build\n/captures\n\n.idea\n\n*.iml\n\n# built application files\n*.apk\n*.ap_\n\n!/apk/app-rel"
  },
  {
    "path": "LICENSE",
    "chars": 10253,
    "preview": "Apache License\nVersion 2.0, January 2004\nhttp://www.apache.org/licenses/\n\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AN"
  },
  {
    "path": "README.md",
    "chars": 1672,
    "preview": "#Gank4Android\r\n\r\n> Deprecated 推荐使用更加简介的[DailyGank](https://github.com/zzhoujay/DailyGank)\r\n\r\n> 使用`Groovy`开发的`Gank.IO` `A"
  },
  {
    "path": "app/.gitignore",
    "chars": 7,
    "preview": "/build\n"
  },
  {
    "path": "app/build.gradle",
    "chars": 1613,
    "preview": "apply plugin: 'com.android.application'\n\nbuildscript {\n    repositories {\n        jcenter()\n    }\n    dependencies {\n   "
  },
  {
    "path": "app/proguard-rules.pro",
    "chars": 662,
    "preview": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /U"
  },
  {
    "path": "app/src/androidTest/java/zhou/gank/io/ApplicationTest.java",
    "chars": 343,
    "preview": "package zhou.gank.io;\n\nimport android.app.Application;\nimport android.test.ApplicationTestCase;\n\n/**\n * <a href=\"http://"
  },
  {
    "path": "app/src/main/AndroidManifest.xml",
    "chars": 1757,
    "preview": "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"zhou.gank.io\">\n\n    <uses-permission a"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/App.groovy",
    "chars": 4972,
    "preview": "package zhou.gank.io\n\nimport android.app.Activity\nimport android.app.Application\nimport android.content.ClipData\nimport "
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/MainActivity.groovy",
    "chars": 3194,
    "preview": "package zhou.gank.io\n\nimport android.animation.Animator\nimport android.animation.AnimatorListenerAdapter\nimport android."
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/comment/Config.groovy",
    "chars": 2603,
    "preview": "package zhou.gank.io.comment\n\nimport android.content.SharedPreferences\nimport android.preference.PreferenceManager\nimpor"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/data/CollectProvider.groovy",
    "chars": 1230,
    "preview": "package zhou.gank.io.data\n\nimport android.support.annotation.Nullable;\nimport groovy.transform.CompileStatic\nimport zhou"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/data/DataManager.groovy",
    "chars": 5250,
    "preview": "package zhou.gank.io.data\n\nimport android.util.Log\nimport groovy.transform.CompileStatic\n\n@CompileStatic\nclass DataManag"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/data/DataProvider.groovy",
    "chars": 1099,
    "preview": "package zhou.gank.io.data\n\nimport android.support.annotation.NonNull\nimport android.support.annotation.Nullable\nimport g"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/data/RandomProvider.groovy",
    "chars": 2949,
    "preview": "package zhou.gank.io.data\n\nimport android.support.annotation.NonNull\nimport android.support.annotation.Nullable\nimport g"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/data/TimeProvider.groovy",
    "chars": 4499,
    "preview": "package zhou.gank.io.data\n\nimport android.support.annotation.NonNull\nimport android.support.annotation.Nullable\nimport g"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/data/TypeProvider.groovy",
    "chars": 3755,
    "preview": "package zhou.gank.io.data\n\nimport android.support.annotation.NonNull\nimport android.support.annotation.Nullable\nimport g"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/database/DatabaseManager.groovy",
    "chars": 3915,
    "preview": "package zhou.gank.io.database\n\nimport android.content.ContentValues\nimport android.content.Context\nimport android.databa"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/model/BaseResult.groovy",
    "chars": 190,
    "preview": "package zhou.gank.io.model\n\nimport groovy.transform.CompileStatic;\n\n@CompileStatic\nabstract class BaseResult implements "
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/model/Bookmark.groovy",
    "chars": 709,
    "preview": "package zhou.gank.io.model;\n\nimport groovy.transform.CompileStatic\n\n@CompileStatic\npublic class Bookmark implements Seri"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/model/Gank.groovy",
    "chars": 1510,
    "preview": "package zhou.gank.io.model\n\nimport groovy.transform.CompileStatic\nimport groovy.transform.EqualsAndHashCode\nimport groov"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/model/GankDaily.groovy",
    "chars": 909,
    "preview": "package zhou.gank.io.model\n\nimport groovy.transform.CompileStatic\nimport groovy.transform.ToString;\n\n@CompileStatic\n@ToS"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/model/Result.groovy",
    "chars": 523,
    "preview": "package zhou.gank.io.model\n\nimport groovy.transform.CompileStatic;\n\n@CompileStatic\nclass Result extends BaseResult {\n\n  "
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/model/ResultDaily.groovy",
    "chars": 584,
    "preview": "package zhou.gank.io.model\n\nimport groovy.transform.CompileStatic\nimport groovy.transform.ToString;\n\n@CompileStatic\n@ToS"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/net/NetworkManager.groovy",
    "chars": 3610,
    "preview": "package zhou.gank.io.net\n\nimport android.content.Context\nimport android.net.ConnectivityManager\nimport android.net.Netwo"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/activity/CollectActivity.groovy",
    "chars": 711,
    "preview": "package zhou.gank.io.ui.activity\n\nimport android.os.Bundle\nimport android.support.annotation.Nullable;\nimport groovy.tra"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/activity/DailyActivity.groovy",
    "chars": 3196,
    "preview": "package zhou.gank.io.ui.activity\n\nimport android.content.Intent\nimport android.os.Bundle\nimport android.support.annotati"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/activity/HomeActivity.groovy",
    "chars": 5740,
    "preview": "package zhou.gank.io.ui.activity\n\nimport android.content.Intent\nimport android.os.Bundle\nimport android.support.design.w"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/activity/ImageGalleryActivity.groovy",
    "chars": 703,
    "preview": "package zhou.gank.io.ui.activity\n\nimport android.content.Intent\nimport android.os.Bundle\nimport android.support.annotati"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/activity/SettingActivity.groovy",
    "chars": 526,
    "preview": "package zhou.gank.io.ui.activity\n\nimport android.os.Bundle\nimport groovy.transform.CompileStatic\nimport zhou.gank.io.R\ni"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/activity/TabActivity.groovy",
    "chars": 3418,
    "preview": "package zhou.gank.io.ui.activity\n\nimport android.content.Intent\nimport android.os.Bundle\nimport android.support.annotati"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/activity/ToolbarActivity.groovy",
    "chars": 2049,
    "preview": "package zhou.gank.io.ui.activity\n\nimport android.os.Bundle\nimport android.support.annotation.Nullable\nimport android.sup"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/activity/WebActivity.groovy",
    "chars": 760,
    "preview": "package zhou.gank.io.ui.activity\n\nimport android.os.Bundle\nimport android.support.annotation.Nullable\nimport groovy.tran"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/adapter/BaseAdapter.groovy",
    "chars": 700,
    "preview": "package zhou.gank.io.ui.adapter\n\nimport android.support.v7.widget.RecyclerView\nimport groovy.transform.CompileStatic\nimp"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/adapter/DailyAdapter.groovy",
    "chars": 2141,
    "preview": "package zhou.gank.io.ui.adapter\n\nimport android.support.v7.widget.CardView\nimport android.support.v7.widget.RecyclerView"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/adapter/GankAdapter.groovy",
    "chars": 2649,
    "preview": "package zhou.gank.io.ui.adapter\n\nimport android.support.v7.widget.CardView\nimport android.support.v7.widget.RecyclerView"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/adapter/ImageAdapter.groovy",
    "chars": 2383,
    "preview": "package zhou.gank.io.ui.adapter\n\nimport android.support.v7.widget.CardView\nimport android.support.v7.widget.RecyclerView"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/adapter/ImageGalleryAdapter.groovy",
    "chars": 2072,
    "preview": "package zhou.gank.io.ui.adapter\n\nimport android.content.Context\nimport android.support.v4.view.PagerAdapter\nimport andro"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/dialog/InfoDialog.groovy",
    "chars": 1679,
    "preview": "package zhou.gank.io.ui.dialog\n\nimport android.app.Dialog\nimport android.os.Bundle\nimport android.support.annotation.Nul"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/fragment/AdvanceFragment.groovy",
    "chars": 1778,
    "preview": "package zhou.gank.io.ui.fragment\n\nimport android.os.Bundle\nimport android.support.annotation.Nullable\nimport android.sup"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/fragment/BaseFragment.groovy",
    "chars": 1650,
    "preview": "package zhou.gank.io.ui.fragment\n\nimport android.app.Activity\nimport android.support.v4.app.Fragment\nimport android.supp"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/fragment/DailyFragment.groovy",
    "chars": 9248,
    "preview": "package zhou.gank.io.ui.fragment\n\nimport android.os.Bundle\nimport android.support.annotation.Nullable\nimport android.sup"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/fragment/GankFragment.groovy",
    "chars": 10493,
    "preview": "package zhou.gank.io.ui.fragment\n\nimport android.content.Intent\nimport android.net.Uri\nimport android.os.Bundle\nimport a"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/fragment/ImageFragment.groovy",
    "chars": 1881,
    "preview": "package zhou.gank.io.ui.fragment\n\nimport android.os.Bundle\nimport android.support.annotation.Nullable\nimport android.sup"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/fragment/ImageGalleryFragment.groovy",
    "chars": 4887,
    "preview": "package zhou.gank.io.ui.fragment\n\nimport android.content.Intent\nimport android.graphics.Bitmap\nimport android.graphics.d"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/fragment/ImagePageFragment.groovy",
    "chars": 1820,
    "preview": "package zhou.gank.io.ui.fragment\n\nimport android.content.Intent\nimport android.os.Bundle\nimport android.support.annotati"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/fragment/SettingFragment.groovy",
    "chars": 1349,
    "preview": "package zhou.gank.io.ui.fragment\n\nimport android.os.Bundle\nimport android.preference.ListPreference\nimport android.prefe"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/fragment/WebFragment.groovy",
    "chars": 6336,
    "preview": "package zhou.gank.io.ui.fragment\n\nimport android.content.Intent\nimport android.net.Uri\nimport android.os.Bundle\nimport a"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/weiget/SwipeToRefreshLayout.groovy",
    "chars": 1020,
    "preview": "package zhou.gank.io.ui.weiget\n\nimport android.content.Context\nimport android.support.v4.widget.SwipeRefreshLayout\nimpor"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/weiget/TouchImageView.java",
    "chars": 42717,
    "preview": "package zhou.gank.io.ui.weiget;\n\n\n/*\n * TouchImageView.java\n * By: Michael Ortiz\n * Updated By: Patrick Lackemacher\n * U"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/ui/weiget/URLSpanNoUnderline.groovy",
    "chars": 1293,
    "preview": "package zhou.gank.io.ui.weiget\n\nimport android.content.Intent\nimport android.net.Uri\nimport android.os.Parcel\nimport and"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/util/FileKit.java",
    "chars": 8329,
    "preview": "package zhou.gank.io.util;\n\nimport android.graphics.Bitmap;\nimport android.util.Log;\n\nimport java.io.BufferedOutputStrea"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/util/HashKit.java",
    "chars": 2001,
    "preview": "package zhou.gank.io.util;\n\nimport java.security.MessageDigest;\n\n/**\n * Created by zzhoujay on 2015/7/31 0031.\n * 加密相关工具"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/util/JsonKit.groovy",
    "chars": 6460,
    "preview": "package zhou.gank.io.util\n\nimport com.google.gson.Gson\nimport com.google.gson.JsonArray\nimport com.google.gson.JsonEleme"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/util/LogKit.java",
    "chars": 2798,
    "preview": "package zhou.gank.io.util;\n\nimport android.util.Log;\n\n/**\n * Created by zzhoujay on 2015/8/22 0022.\n * LogKit 可以设置日志级别\n "
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/util/NetworkKit.groovy",
    "chars": 1235,
    "preview": "package zhou.gank.io.util\n\nimport com.squareup.okhttp.Request\nimport groovy.transform.CompileStatic\nimport zhou.gank.io."
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/util/Notifier.groovy",
    "chars": 143,
    "preview": "package zhou.gank.io.util;\n\nimport groovy.transform.CompileStatic\n\n@CompileStatic\npublic interface Notifier {\n\n    void "
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/util/NumKit.groovy",
    "chars": 313,
    "preview": "package zhou.gank.io.util;\n\nimport groovy.transform.CompileStatic\n\n@CompileStatic\npublic class NumKit {\n\n\n    public sta"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/util/Pageable.groovy",
    "chars": 387,
    "preview": "package zhou.gank.io.util\n\nimport groovy.transform.CompileStatic;\n\n@CompileStatic\nclass Pageable implements Serializable"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/util/TextKit.groovy",
    "chars": 2265,
    "preview": "package zhou.gank.io.util\n\nimport android.graphics.Typeface\nimport android.text.SpannableStringBuilder\nimport android.te"
  },
  {
    "path": "app/src/main/groovy/zhou/gank/io/util/TimeKit.groovy",
    "chars": 898,
    "preview": "package zhou.gank.io.util;\n\nimport groovy.transform.CompileStatic\n\nimport java.text.SimpleDateFormat\n\n@CompileStatic\npub"
  },
  {
    "path": "app/src/main/res/drawable/ic_bookmark_48px.xml",
    "chars": 732,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:bett"
  },
  {
    "path": "app/src/main/res/drawable/ic_cloud_off_48px.xml",
    "chars": 1408,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_cloud_queue_48px.xml",
    "chars": 1224,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_dashboard_48px.xml",
    "chars": 778,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_event_48px.xml",
    "chars": 974,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_extension_48px.xml",
    "chars": 1302,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_favorite_white_48px.xml",
    "chars": 916,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_info_48px.xml",
    "chars": 852,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_insert_emoticon_48px.xml",
    "chars": 1444,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_menu_white_48px.xml",
    "chars": 708,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_refresh_48px.xml",
    "chars": 1062,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_settings_black_48px.xml",
    "chars": 2332,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/drawable/ic_view_module_48px.xml",
    "chars": 904,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:better=\""
  },
  {
    "path": "app/src/main/res/layout/activity_compat.xml",
    "chars": 262,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.design.widget.CoordinatorLayout xmlns:android=\"http://schemas.an"
  },
  {
    "path": "app/src/main/res/layout/activity_home.xml",
    "chars": 955,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.v4.widget.DrawerLayout xmlns:android=\"http://schemas.android.com"
  },
  {
    "path": "app/src/main/res/layout/activity_main.xml",
    "chars": 1264,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.design.widget.CoordinatorLayout xmlns:android=\"http://schemas.an"
  },
  {
    "path": "app/src/main/res/layout/activity_tab.xml",
    "chars": 1816,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.design.widget.CoordinatorLayout xmlns:android=\"http://schemas.an"
  },
  {
    "path": "app/src/main/res/layout/activity_toolbar.xml",
    "chars": 1313,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.design.widget.CoordinatorLayout xmlns:android=\"http://schemas.an"
  },
  {
    "path": "app/src/main/res/layout/dialog_text.xml",
    "chars": 468,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<TextView xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:"
  },
  {
    "path": "app/src/main/res/layout/fragment_daily.xml",
    "chars": 5268,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.design.widget.CoordinatorLayout xmlns:android=\"http://schemas.an"
  },
  {
    "path": "app/src/main/res/layout/fragment_image_page.xml",
    "chars": 254,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ImageView xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android"
  },
  {
    "path": "app/src/main/res/layout/fragment_recyler_view.xml",
    "chars": 1784,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.design.widget.CoordinatorLayout xmlns:android=\"http://schemas.an"
  },
  {
    "path": "app/src/main/res/layout/fragment_viewpager.xml",
    "chars": 220,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.v4.view.ViewPager\n    xmlns:android=\"http://schemas.android.com/"
  },
  {
    "path": "app/src/main/res/layout/fragment_web.xml",
    "chars": 1237,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xm"
  },
  {
    "path": "app/src/main/res/layout/item_daily.xml",
    "chars": 1559,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.v7.widget.CardView xmlns:android=\"http://schemas.android.com/apk"
  },
  {
    "path": "app/src/main/res/layout/item_gank.xml",
    "chars": 2083,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.v7.widget.CardView xmlns:android=\"http://schemas.android.com/apk"
  },
  {
    "path": "app/src/main/res/layout/item_image.xml",
    "chars": 1815,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.v7.widget.CardView xmlns:android=\"http://schemas.android.com/apk"
  },
  {
    "path": "app/src/main/res/layout/layout_gallery.xml",
    "chars": 1826,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<android.support.design.widget.CoordinatorLayout xmlns:android=\"http://schemas.an"
  },
  {
    "path": "app/src/main/res/layout/layout_more.xml",
    "chars": 1379,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    andro"
  },
  {
    "path": "app/src/main/res/layout/nav_header.xml",
    "chars": 1038,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    an"
  },
  {
    "path": "app/src/main/res/menu/drawer_view.xml",
    "chars": 1477,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\">\n\n    <item andr"
  },
  {
    "path": "app/src/main/res/menu/menu_pop.xml",
    "chars": 206,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\">\n    <item\n     "
  },
  {
    "path": "app/src/main/res/menu/menu_pop_add.xml",
    "chars": 196,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\">\n    <item andro"
  },
  {
    "path": "app/src/main/res/menu/menu_pop_remove.xml",
    "chars": 210,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\">\n    <item\n     "
  },
  {
    "path": "app/src/main/res/menu/menu_web.xml",
    "chars": 391,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\">\n    <item\n     "
  },
  {
    "path": "app/src/main/res/values/colors.xml",
    "chars": 15720,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n\n    <color name=\"loading_background\">#55000000</color>\n\n    <color n"
  },
  {
    "path": "app/src/main/res/values/dimens.xml",
    "chars": 646,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <dimen name=\"fab_margin\">16dp</dimen>\n    <dimen name=\"detail_bac"
  },
  {
    "path": "app/src/main/res/values/strings.xml",
    "chars": 4028,
    "preview": "<resources>\n    <string name=\"app_name\">干货集中营</string>\n\n    <string name=\"loading\">加载中。。。</string>\n    <string name=\"no_"
  },
  {
    "path": "app/src/main/res/values/styles.xml",
    "chars": 777,
    "preview": "<resources>\n\n    <!-- Base application theme. -->\n    <style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.NoActionBar\">"
  },
  {
    "path": "app/src/main/res/values-en/strings.xml",
    "chars": 2931,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <string name=\"app_name\">Gank.IO</string>\n    <string name=\"confir"
  },
  {
    "path": "app/src/main/res/values-v21/styles.xml",
    "chars": 2336,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n\n    <style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.NoActionBar"
  },
  {
    "path": "app/src/main/res/xml/setting.xml",
    "chars": 1459,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<PreferenceScreen xmlns:android=\"http://schemas.android.com/apk/res/android\">\n   "
  },
  {
    "path": "build.gradle",
    "chars": 436,
    "preview": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n    r"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "chars": 236,
    "preview": "#Tue Sep 22 23:09:57 GMT+08:00 2015\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE"
  },
  {
    "path": "gradle.properties",
    "chars": 855,
    "preview": "# Project-wide Gradle settings.\n\n# IDE (e.g. Android Studio) users:\n# Gradle settings configured through the IDE *will o"
  },
  {
    "path": "gradlew",
    "chars": 5080,
    "preview": "#!/usr/bin/env bash\n\n##############################################################################\n##\n##  Gradle start "
  },
  {
    "path": "gradlew.bat",
    "chars": 2314,
    "preview": "@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem "
  },
  {
    "path": "settings.gradle",
    "chars": 15,
    "preview": "include ':app'\n"
  }
]

// ... and 1 more files (download for full content)

About this extraction

This page contains the full source code of the zzhoujay/Gank4Android GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 110 files (268.2 KB), approximately 71.7k tokens, and a symbol index with 128 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!