├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── libraries
│ ├── appcompat_v7_22_2_0.xml
│ ├── butterknife_6_1_0.xml
│ ├── cardview_v7_22_2_0.xml
│ ├── eventbus_2_4_0.xml
│ ├── freemarker_2_3_20.xml
│ ├── greendao_1_3_0_beta_1.xml
│ ├── greendao_generator_1_3_1.xml
│ ├── gson_2_2_4.xml
│ ├── haha_1_3.xml
│ ├── leakcanary_analyzer_1_3_1.xml
│ ├── leakcanary_android_1_3_1.xml
│ ├── leakcanary_watcher_1_3_1.xml
│ ├── lib_1_0_1.xml
│ ├── library_1_0_19.xml
│ ├── material_dialogs_0_7_3_1.xml
│ ├── okhttp_2_5_0.xml
│ ├── okhttp_urlconnection_2_5_0.xml
│ ├── okio_1_6_0.xml
│ ├── recyclerview_v7_22_2_0.xml
│ ├── support_annotations_22_2_0.xml
│ ├── support_v4_22_2_0.xml
│ ├── uk_co_senab_photoview_source.xml
│ └── universal_image_loader_1_9_3.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
├── vcs.xml
└── workspace.xml
├── GreenDaoGenerator
├── .gitignore
├── GreenDaoGenerator.iml
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── socks
│ └── MyDaoGenerator.java
├── JianDan.iml
├── JianDan_OkHttpWithVolley.iml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── libs
│ ├── butterknife-6.1.0.jar
│ ├── greendao-1.3.0-beta-1.jar
│ ├── gson-2.2.4.jar
│ ├── uk-co-senab-photoview-source.jar
│ └── universal-image-loader-1.9.3.jar
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── socks
│ │ └── jiandan
│ │ ├── ApplicationTest.java
│ │ └── TestClass.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ └── style.css
│ ├── java-gen
│ └── com
│ │ └── socks
│ │ └── greendao
│ │ ├── DaoMaster.java
│ │ ├── DaoSession.java
│ │ ├── FreshNewsCache.java
│ │ ├── FreshNewsCacheDao.java
│ │ ├── JokeCache.java
│ │ ├── JokeCacheDao.java
│ │ ├── PictureCache.java
│ │ ├── PictureCacheDao.java
│ │ ├── SisterCache.java
│ │ ├── SisterCacheDao.java
│ │ ├── VideoCache.java
│ │ └── VideoCacheDao.java
│ ├── java
│ └── com
│ │ └── socks
│ │ └── jiandan
│ │ ├── adapter
│ │ ├── CommentAdapter.java
│ │ ├── FreshNewsAdapter.java
│ │ ├── JokeAdapter.java
│ │ ├── PictureAdapter.java
│ │ └── VideoAdapter.java
│ │ ├── base
│ │ ├── BaseActivity.java
│ │ ├── BaseFragment.java
│ │ ├── ConstantString.java
│ │ └── JDApplication.java
│ │ ├── cache
│ │ ├── BaseCache.java
│ │ ├── FreshNewsCache.java
│ │ ├── JokeCache.java
│ │ ├── PictureCache.java
│ │ ├── SisterCache.java
│ │ └── VideoCache.java
│ │ ├── callback
│ │ ├── LoadFinishCallBack.java
│ │ ├── LoadMoreListener.java
│ │ └── LoadResultCallBack.java
│ │ ├── model
│ │ ├── Author.java
│ │ ├── Comment4FreshNews.java
│ │ ├── CommentNumber.java
│ │ ├── Commentator.java
│ │ ├── CustomFields.java
│ │ ├── FreshNews.java
│ │ ├── Joke.java
│ │ ├── MenuItem.java
│ │ ├── NetWorkEvent.java
│ │ ├── Picture.java
│ │ ├── Tags.java
│ │ ├── Video.java
│ │ └── Vote.java
│ │ ├── net
│ │ ├── JSONParser.java
│ │ ├── OkHttpStack.java
│ │ ├── Request4CommentCounts.java
│ │ ├── Request4CommentList.java
│ │ ├── Request4FreshNews.java
│ │ ├── Request4FreshNewsCommentList.java
│ │ ├── Request4FreshNewsDetail.java
│ │ ├── Request4Joke.java
│ │ ├── Request4Picture.java
│ │ ├── Request4PushComment.java
│ │ ├── Request4PushFreshComment.java
│ │ ├── Request4Video.java
│ │ ├── Request4Vote.java
│ │ └── RequestManager.java
│ │ ├── ui
│ │ ├── CommentListActivity.java
│ │ ├── FreshNewsDetailActivity.java
│ │ ├── ImageDetailActivity.java
│ │ ├── MainActivity.java
│ │ ├── PushCommentActivity.java
│ │ ├── SettingActivity.java
│ │ ├── VideoDetailActivity.java
│ │ └── fragment
│ │ │ ├── FreshNewsDetailFragment.java
│ │ │ ├── FreshNewsFragment.java
│ │ │ ├── JokeFragment.java
│ │ │ ├── MainMenuFragment.java
│ │ │ ├── PictureFragment.java
│ │ │ ├── SettingFragment.java
│ │ │ ├── SisterFragment.java
│ │ │ └── VideoFragment.java
│ │ ├── utils
│ │ ├── ActivityManager.java
│ │ ├── AppInfoUtil.java
│ │ ├── CacheUtil.java
│ │ ├── EditTextShakeHelper.java
│ │ ├── FileUtil.java
│ │ ├── JDMediaScannerConnectionClient.java
│ │ ├── NetWorkUtil.java
│ │ ├── ScreenSizeUtil.java
│ │ ├── ShareUtil.java
│ │ ├── SharedPreUtils.java
│ │ ├── ShowToast.java
│ │ ├── StrictModeUtil.java
│ │ ├── String2TimeUtil.java
│ │ ├── TextUtil.java
│ │ └── logger
│ │ │ ├── LogLevel.java
│ │ │ └── Logger.java
│ │ └── view
│ │ ├── AutoLoadRecyclerView.java
│ │ ├── FadeInAnimator.java
│ │ ├── MyItemAnimator.java
│ │ ├── ShowMaxImageView.java
│ │ ├── floorview
│ │ ├── Commentable.java
│ │ ├── FloorView.java
│ │ ├── SubComments.java
│ │ └── SubFloorFactory.java
│ │ └── imageloader
│ │ └── ImageLoadProxy.java
│ └── res
│ ├── anim
│ ├── anim_none.xml
│ ├── item_bottom_in.xml
│ └── trans_center_2_right.xml
│ ├── drawable-hdpi
│ ├── ic_action_refresh.png
│ ├── ic_actionbar_back.png
│ ├── ic_chat_white_24dp.png
│ ├── ic_comment_down_arrow.png
│ ├── ic_explore_white_24dp.png
│ ├── ic_loading_large.png
│ ├── ic_loading_small.png
│ ├── ic_mood_white_24dp.png
│ ├── ic_more.png
│ ├── ic_more_horiz_grey600_24dp.png
│ ├── ic_movie_white_24dp.png
│ ├── ic_play_gif.png
│ ├── progress_bg_holo_dark.9.png
│ ├── progress_primary_holo_dark.9.png
│ ├── progress_secondary_holo_dark.9.png
│ ├── progressbar_indeterminate_holo1.png
│ ├── progressbar_indeterminate_holo2.png
│ ├── progressbar_indeterminate_holo3.png
│ ├── progressbar_indeterminate_holo4.png
│ ├── progressbar_indeterminate_holo5.png
│ ├── progressbar_indeterminate_holo6.png
│ ├── progressbar_indeterminate_holo7.png
│ ├── progressbar_indeterminate_holo8.png
│ └── widget_bottom_shadow.9.png
│ ├── drawable-xhdpi
│ ├── comment_item_card_background.9.png
│ ├── drawer_shadow.9.png
│ ├── ic_action_chat.png
│ ├── ic_action_copy.png
│ ├── ic_action_download.png
│ ├── ic_action_edit.png
│ ├── ic_action_refresh.png
│ ├── ic_action_refresh_black.png
│ ├── ic_action_reply.png
│ ├── ic_action_send_now.png
│ ├── ic_action_share.png
│ ├── ic_action_share_black.png
│ ├── ic_action_share_moment.png
│ ├── ic_action_share_other.png
│ ├── ic_action_share_wechat.png
│ ├── ic_action_share_weibo.png
│ ├── ic_brightness_day_white_24dp.png
│ ├── ic_brightness_night_white_24dp.png
│ ├── ic_chat_white_24dp.png
│ ├── ic_chevron_left_white_36dp.png
│ ├── ic_chevron_right_white_36dp.png
│ ├── ic_close_white_24dp.png
│ ├── ic_drawer.png
│ ├── ic_explore_white_24dp.png
│ ├── ic_launcher.png
│ ├── ic_local_florist_white_24dp.png
│ ├── ic_mood_white_24dp.png
│ ├── ic_more_horiz_grey600_24dp.png
│ ├── ic_movie_white_24dp.png
│ ├── ic_settings_white_24dp.png
│ ├── ic_stat_av_upload.png
│ ├── ic_stat_navigation_accept.png
│ ├── ic_stat_navigation_cancel.png
│ ├── post_list_item_bottom.9.png
│ ├── post_list_item_top.9.png
│ ├── progress_bg_holo_dark.9.png
│ ├── progress_primary_holo_dark.9.png
│ ├── progress_secondary_holo_dark.9.png
│ ├── progressbar_indeterminate_holo1.png
│ ├── progressbar_indeterminate_holo2.png
│ ├── progressbar_indeterminate_holo3.png
│ ├── progressbar_indeterminate_holo4.png
│ ├── progressbar_indeterminate_holo5.png
│ ├── progressbar_indeterminate_holo6.png
│ ├── progressbar_indeterminate_holo7.png
│ ├── progressbar_indeterminate_holo8.png
│ ├── vpi__tab_selected_focused_holo.9.png
│ ├── vpi__tab_selected_holo.9.png
│ ├── vpi__tab_selected_pressed_holo.9.png
│ ├── vpi__tab_unselected_focused_holo.9.png
│ ├── vpi__tab_unselected_holo.9.png
│ ├── vpi__tab_unselected_pressed_holo.9.png
│ └── widget_bottom_shadow.9.png
│ ├── drawable-xxhdpi
│ ├── drawer_shadow.9.png
│ ├── ic_action_back.png
│ ├── ic_action_chat.png
│ ├── ic_action_copy.png
│ ├── ic_action_download.png
│ ├── ic_action_edit.png
│ ├── ic_action_refresh.png
│ ├── ic_action_refresh_black.png
│ ├── ic_action_reply.png
│ ├── ic_action_send_now.png
│ ├── ic_action_share.png
│ ├── ic_action_share_black.png
│ ├── ic_action_share_moment.png
│ ├── ic_action_share_other.png
│ ├── ic_action_share_wechat.png
│ ├── ic_action_share_weibo.png
│ ├── ic_brightness_day_white_24dp.png
│ ├── ic_brightness_night_white_24dp.png
│ ├── ic_chat_white_24dp.png
│ ├── ic_chevron_left_white_36dp.png
│ ├── ic_chevron_right_white_36dp.png
│ ├── ic_close_white_24dp.png
│ ├── ic_drawer.png
│ ├── ic_explore_white_24dp.png
│ ├── ic_launcher.png
│ ├── ic_local_florist_white_24dp.png
│ ├── ic_mood_white_24dp.png
│ ├── ic_more_horiz_grey600_24dp.png
│ ├── ic_movie_white_24dp.png
│ ├── ic_play_gif.png
│ ├── ic_settings_white_24dp.png
│ ├── ic_stat_av_upload.png
│ ├── ic_stat_navigation_accept.png
│ ├── ic_stat_navigation_cancel.png
│ ├── progress_bg_holo_dark.9.png
│ ├── progress_primary_holo_dark.9.png
│ ├── progress_secondary_holo_dark.9.png
│ ├── progressbar_indeterminate_holo1.png
│ ├── progressbar_indeterminate_holo2.png
│ ├── progressbar_indeterminate_holo3.png
│ ├── progressbar_indeterminate_holo4.png
│ ├── progressbar_indeterminate_holo5.png
│ ├── progressbar_indeterminate_holo6.png
│ ├── progressbar_indeterminate_holo7.png
│ └── progressbar_indeterminate_holo8.png
│ ├── drawable
│ ├── bg_comment.xml
│ ├── bg_floor.9.png
│ ├── progress_horizontal_holo_dark.xml
│ ├── progress_indeterminate_horizontal_holo.xml
│ └── progressbar_horizontal_blue.xml
│ ├── layout
│ ├── activity_comment_list.xml
│ ├── activity_fresh_news_detail.xml
│ ├── activity_image_detail.xml
│ ├── activity_main.xml
│ ├── activity_push_comment.xml
│ ├── activity_setting.xml
│ ├── activity_video_detail.xml
│ ├── common_loading.xml
│ ├── common_toolbar.xml
│ ├── dialog_commentotar_info.xml
│ ├── drawer_item.xml
│ ├── fragment_auto_load.xml
│ ├── fragment_drawer.xml
│ ├── fragment_fresh_news_detail.xml
│ ├── item_comment.xml
│ ├── item_comment_flag.xml
│ ├── item_comment_floor.xml
│ ├── item_fresh_news.xml
│ ├── item_fresh_news_small.xml
│ ├── item_joke.xml
│ ├── item_pic.xml
│ └── item_video.xml
│ ├── menu
│ ├── menu_comment_list.xml
│ ├── menu_fresh_news_detail.xml
│ ├── menu_push_comment.xml
│ ├── menu_refresh.xml
│ └── menu_video_detail.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-v21
│ └── styles.xml
│ ├── values-w820dp
│ └── dimens.xml
│ ├── values
│ ├── arrays.xml
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
│ └── xml
│ └── preferences.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
└── demo.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea
2 | # Built application files
3 | *.apk
4 | *.ap_
5 |
6 | # Files for the Dalvik VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # Generated files
13 | bin/
14 | gen/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 | /*/build/
20 |
21 | # Local configuration file (sdk path, etc)
22 | local.properties
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | # Log Files
28 | *.log
29 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | JianDan_OkHttpWithVolley
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/libraries/appcompat_v7_22_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/butterknife_6_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/cardview_v7_22_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/eventbus_2_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/freemarker_2_3_20.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/greendao_1_3_0_beta_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/greendao_generator_1_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/gson_2_2_4.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/haha_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/leakcanary_analyzer_1_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/leakcanary_android_1_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/leakcanary_watcher_1_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/lib_1_0_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/library_1_0_19.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/material_dialogs_0_7_3_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/okhttp_2_5_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/okhttp_urlconnection_2_5_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/okio_1_6_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/recyclerview_v7_22_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/support_annotations_22_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/support_v4_22_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/libraries/uk_co_senab_photoview_source.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/universal_image_loader_1_9_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/GreenDaoGenerator/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/GreenDaoGenerator/GreenDaoGenerator.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/GreenDaoGenerator/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | repositories {
4 | mavenLocal()
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | compile 'de.greenrobot:greendao-generator:1.3.1'
10 | }
11 |
12 | sourceSets {
13 | main {
14 | java {
15 | srcDir 'src/main/java'
16 | }
17 | }
18 | }
19 | artifacts {
20 | archives jar
21 | }
--------------------------------------------------------------------------------
/GreenDaoGenerator/src/main/java/com/socks/MyDaoGenerator.java:
--------------------------------------------------------------------------------
1 | package com.socks;
2 |
3 | /**
4 | * Created by zhaokaiqiang on 15/5/11.
5 | */
6 |
7 | import de.greenrobot.daogenerator.DaoGenerator;
8 | import de.greenrobot.daogenerator.Entity;
9 | import de.greenrobot.daogenerator.Schema;
10 |
11 | /**
12 | * 用来为GreenDao框架生成Dao文件
13 | */
14 | public class MyDaoGenerator {
15 |
16 | //辅助文件生成的相对路径
17 | public static final String DAO_PATH = "../app/src/main/java-gen";
18 | //辅助文件的包名
19 | public static final String PACKAGE_NAME = "com.socks.greendao";
20 | //数据库的版本号
21 | public static final int DATA_VERSION_CODE = 1;
22 |
23 | public static void main(String[] args) throws Exception {
24 |
25 | Schema schema = new Schema(DATA_VERSION_CODE, PACKAGE_NAME);
26 | addCache(schema, "JokeCache");
27 | addCache(schema, "FreshNewsCache");
28 | addCache(schema, "PictureCache");
29 | addCache(schema, "SisterCache");
30 | addCache(schema, "VideoCache");
31 | //生成Dao文件路径
32 | new DaoGenerator().generateAll(schema, DAO_PATH);
33 |
34 | }
35 |
36 | /**
37 | * 添加不同的缓存表
38 | * @param schema
39 | * @param tableName
40 | */
41 | private static void addCache(Schema schema, String tableName) {
42 |
43 | Entity joke = schema.addEntity(tableName);
44 |
45 | //主键id自增长
46 | joke.addIdProperty().primaryKey().autoincrement();
47 | //请求结果
48 | joke.addStringProperty("result");
49 | //页数
50 | joke.addIntProperty("page");
51 | //插入时间,暂时无用
52 | joke.addLongProperty("time");
53 |
54 | }
55 |
56 | }
--------------------------------------------------------------------------------
/JianDan.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/JianDan_OkHttpWithVolley.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JianDan客户端高仿版(使用OkHttp替换Volley底层实现的版本)
2 |
3 | ---
4 |
5 | 原始版本请到[这里](https://github.com/ZhaoKaiQiang/JianDan)
6 |
7 | ##效果图
8 |
9 | 废话不多说,先上效果图
10 |
11 | 
12 |
13 | ##关于我
14 | - [Android研发工程师](http://weibo.com/zhaokaiqiang1992)
15 | - [CSDN博客专家](http://blog.csdn.net/zhaokaiqiang1992)
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /app.iml
2 | /build
3 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.0"
6 |
7 | defaultConfig {
8 | applicationId "com.socks.jiandan"
9 | minSdkVersion 14
10 | targetSdkVersion 22
11 | versionCode 2
12 | versionName "1.2"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | lintOptions {
22 | abortOnError false
23 | }
24 |
25 | sourceSets {
26 | main {
27 | java.srcDirs = ['src/main/java', 'src/main/java-gen']
28 | }
29 | }
30 | }
31 |
32 | dependencies {
33 | compile fileTree(dir: 'libs', include: ['*.jar'])
34 | compile 'com.android.support:appcompat-v7:22.2.0'
35 | compile 'com.android.support:cardview-v7:22.2.0'
36 | compile 'com.android.support:recyclerview-v7:22.2.0'
37 | compile 'com.afollestad:material-dialogs:0.7.3.1'
38 | compile 'de.greenrobot:eventbus:2.4.0'
39 | compile 'com.victor:lib:1.0.1'
40 | compile 'com.mcxiaoke.volley:library:1.0.19'
41 | compile 'com.squareup.okio:okio:1.5.0'
42 | compile 'com.squareup.okhttp:okhttp:2.5.0'
43 | compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
44 |
45 | debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
46 | releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
47 | }
48 |
--------------------------------------------------------------------------------
/app/libs/butterknife-6.1.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZhaoKaiQiang/JianDan_OkHttpWithVolley/0e3976edd310235d96501e58e59dc266e275b80b/app/libs/butterknife-6.1.0.jar
--------------------------------------------------------------------------------
/app/libs/greendao-1.3.0-beta-1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZhaoKaiQiang/JianDan_OkHttpWithVolley/0e3976edd310235d96501e58e59dc266e275b80b/app/libs/greendao-1.3.0-beta-1.jar
--------------------------------------------------------------------------------
/app/libs/gson-2.2.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZhaoKaiQiang/JianDan_OkHttpWithVolley/0e3976edd310235d96501e58e59dc266e275b80b/app/libs/gson-2.2.4.jar
--------------------------------------------------------------------------------
/app/libs/uk-co-senab-photoview-source.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZhaoKaiQiang/JianDan_OkHttpWithVolley/0e3976edd310235d96501e58e59dc266e275b80b/app/libs/uk-co-senab-photoview-source.jar
--------------------------------------------------------------------------------
/app/libs/universal-image-loader-1.9.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZhaoKaiQiang/JianDan_OkHttpWithVolley/0e3976edd310235d96501e58e59dc266e275b80b/app/libs/universal-image-loader-1.9.3.jar
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/zhaokaiqiang/Develop/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/socks/jiandan/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/socks/jiandan/TestClass.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan;
2 |
3 | import android.test.InstrumentationTestCase;
4 |
5 | import com.android.volley.Request;
6 | import com.android.volley.Response;
7 | import com.android.volley.VolleyError;
8 | import com.socks.jiandan.base.JDApplication;
9 | import com.socks.jiandan.net.RequestManager;
10 | import com.socks.jiandan.utils.ShowToast;
11 |
12 | /**
13 | * Created by zhaokaiqiang on 15/4/27.
14 | */
15 | public class TestClass extends InstrumentationTestCase{
16 |
17 | public TestClass(){
18 |
19 | }
20 |
21 | public void testGetCommentators() throws Exception {
22 |
23 | JDApplication.getContext();
24 |
25 | }
26 |
27 | protected void executeRequest(Request> request) {
28 | RequestManager.addRequest(request, this);
29 | }
30 |
31 | protected Response.ErrorListener errorListener() {
32 | return new Response.ErrorListener() {
33 | @Override
34 | public void onErrorResponse(VolleyError error) {
35 | ShowToast.Short(error.getMessage());
36 | }
37 | };
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
17 |
18 |
24 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
37 |
40 |
44 |
48 |
51 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/java-gen/com/socks/greendao/FreshNewsCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.greendao;
2 |
3 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
4 | /**
5 | * Entity mapped to table FRESH_NEWS_CACHE.
6 | */
7 | public class FreshNewsCache {
8 |
9 | private Long id;
10 | private String result;
11 | private Integer page;
12 | private Long time;
13 |
14 | public FreshNewsCache() {
15 | }
16 |
17 | public FreshNewsCache(Long id) {
18 | this.id = id;
19 | }
20 |
21 | public FreshNewsCache(Long id, String result, Integer page, Long time) {
22 | this.id = id;
23 | this.result = result;
24 | this.page = page;
25 | this.time = time;
26 | }
27 |
28 | public Long getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Long id) {
33 | this.id = id;
34 | }
35 |
36 | public String getResult() {
37 | return result;
38 | }
39 |
40 | public void setResult(String result) {
41 | this.result = result;
42 | }
43 |
44 | public Integer getPage() {
45 | return page;
46 | }
47 |
48 | public void setPage(Integer page) {
49 | this.page = page;
50 | }
51 |
52 | public Long getTime() {
53 | return time;
54 | }
55 |
56 | public void setTime(Long time) {
57 | this.time = time;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java-gen/com/socks/greendao/JokeCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.greendao;
2 |
3 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
4 | /**
5 | * Entity mapped to table JOKE_CACHE.
6 | */
7 | public class JokeCache {
8 |
9 | private Long id;
10 | private String result;
11 | private Integer page;
12 | private Long time;
13 |
14 | public JokeCache() {
15 | }
16 |
17 | public JokeCache(Long id) {
18 | this.id = id;
19 | }
20 |
21 | public JokeCache(Long id, String result, Integer page, Long time) {
22 | this.id = id;
23 | this.result = result;
24 | this.page = page;
25 | this.time = time;
26 | }
27 |
28 | public Long getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Long id) {
33 | this.id = id;
34 | }
35 |
36 | public String getResult() {
37 | return result;
38 | }
39 |
40 | public void setResult(String result) {
41 | this.result = result;
42 | }
43 |
44 | public Integer getPage() {
45 | return page;
46 | }
47 |
48 | public void setPage(Integer page) {
49 | this.page = page;
50 | }
51 |
52 | public Long getTime() {
53 | return time;
54 | }
55 |
56 | public void setTime(Long time) {
57 | this.time = time;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java-gen/com/socks/greendao/PictureCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.greendao;
2 |
3 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
4 | /**
5 | * Entity mapped to table PICTURE_CACHE.
6 | */
7 | public class PictureCache {
8 |
9 | private Long id;
10 | private String result;
11 | private Integer page;
12 | private Long time;
13 |
14 | public PictureCache() {
15 | }
16 |
17 | public PictureCache(Long id) {
18 | this.id = id;
19 | }
20 |
21 | public PictureCache(Long id, String result, Integer page, Long time) {
22 | this.id = id;
23 | this.result = result;
24 | this.page = page;
25 | this.time = time;
26 | }
27 |
28 | public Long getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Long id) {
33 | this.id = id;
34 | }
35 |
36 | public String getResult() {
37 | return result;
38 | }
39 |
40 | public void setResult(String result) {
41 | this.result = result;
42 | }
43 |
44 | public Integer getPage() {
45 | return page;
46 | }
47 |
48 | public void setPage(Integer page) {
49 | this.page = page;
50 | }
51 |
52 | public Long getTime() {
53 | return time;
54 | }
55 |
56 | public void setTime(Long time) {
57 | this.time = time;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java-gen/com/socks/greendao/SisterCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.greendao;
2 |
3 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
4 | /**
5 | * Entity mapped to table SISTER_CACHE.
6 | */
7 | public class SisterCache {
8 |
9 | private Long id;
10 | private String result;
11 | private Integer page;
12 | private Long time;
13 |
14 | public SisterCache() {
15 | }
16 |
17 | public SisterCache(Long id) {
18 | this.id = id;
19 | }
20 |
21 | public SisterCache(Long id, String result, Integer page, Long time) {
22 | this.id = id;
23 | this.result = result;
24 | this.page = page;
25 | this.time = time;
26 | }
27 |
28 | public Long getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Long id) {
33 | this.id = id;
34 | }
35 |
36 | public String getResult() {
37 | return result;
38 | }
39 |
40 | public void setResult(String result) {
41 | this.result = result;
42 | }
43 |
44 | public Integer getPage() {
45 | return page;
46 | }
47 |
48 | public void setPage(Integer page) {
49 | this.page = page;
50 | }
51 |
52 | public Long getTime() {
53 | return time;
54 | }
55 |
56 | public void setTime(Long time) {
57 | this.time = time;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java-gen/com/socks/greendao/VideoCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.greendao;
2 |
3 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
4 | /**
5 | * Entity mapped to table VIDEO_CACHE.
6 | */
7 | public class VideoCache {
8 |
9 | private Long id;
10 | private String result;
11 | private Integer page;
12 | private Long time;
13 |
14 | public VideoCache() {
15 | }
16 |
17 | public VideoCache(Long id) {
18 | this.id = id;
19 | }
20 |
21 | public VideoCache(Long id, String result, Integer page, Long time) {
22 | this.id = id;
23 | this.result = result;
24 | this.page = page;
25 | this.time = time;
26 | }
27 |
28 | public Long getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Long id) {
33 | this.id = id;
34 | }
35 |
36 | public String getResult() {
37 | return result;
38 | }
39 |
40 | public void setResult(String result) {
41 | this.result = result;
42 | }
43 |
44 | public Integer getPage() {
45 | return page;
46 | }
47 |
48 | public void setPage(Integer page) {
49 | this.page = page;
50 | }
51 |
52 | public Long getTime() {
53 | return time;
54 | }
55 |
56 | public void setTime(Long time) {
57 | this.time = time;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/socks/jiandan/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 青岛司通科技有限公司 All rights reserved.
3 | * File Name:BaseActivity.java
4 | * Version:V1.0
5 | * Author:zhaokaiqiang
6 | * Date:2014-8-6
7 | */
8 | package com.socks.jiandan.base;
9 |
10 | import android.content.Context;
11 | import android.os.Bundle;
12 | import android.support.v4.app.Fragment;
13 | import android.support.v4.app.FragmentTransaction;
14 | import android.support.v7.app.AppCompatActivity;
15 |
16 | import com.android.volley.Request;
17 | import com.socks.jiandan.BuildConfig;
18 | import com.socks.jiandan.R;
19 | import com.socks.jiandan.net.RequestManager;
20 | import com.socks.jiandan.utils.logger.LogLevel;
21 | import com.socks.jiandan.utils.logger.Logger;
22 |
23 | public abstract class BaseActivity extends AppCompatActivity implements ConstantString {
24 |
25 | protected Context mContext;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | mContext = this;
31 |
32 | if (BuildConfig.DEBUG) {
33 | Logger.init(getClass().getSimpleName()).setLogLevel(LogLevel.FULL).hideThreadInfo();
34 | } else {
35 | Logger.init(getClass().getSimpleName()).setLogLevel(LogLevel.NONE).hideThreadInfo();
36 | }
37 | }
38 |
39 | @Override
40 | public void finish() {
41 | super.finish();
42 | overridePendingTransition(R.anim.anim_none, R.anim.trans_center_2_right);
43 | }
44 |
45 | @Override
46 | protected void onDestroy() {
47 | super.onDestroy();
48 | JDApplication.getRefWatcher(this).watch(this);
49 | RequestManager.cancelAll(this);
50 | }
51 |
52 | ///////////////////////////////////////////////////////////////////////////
53 | // Abstract Method In Activity
54 | ///////////////////////////////////////////////////////////////////////////
55 |
56 | protected abstract void initView();
57 |
58 | protected abstract void initData();
59 |
60 | ///////////////////////////////////////////////////////////////////////////
61 | // Common Operation
62 | ///////////////////////////////////////////////////////////////////////////
63 |
64 | public void replaceFragment(int id_content, Fragment fragment) {
65 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
66 | transaction.replace(id_content, fragment);
67 | transaction.commit();
68 | }
69 |
70 | public void executeRequest(Request> request) {
71 | RequestManager.addRequest(request, this);
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/socks/jiandan/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 |
6 | import com.android.volley.Request;
7 | import com.socks.jiandan.BuildConfig;
8 | import com.socks.jiandan.net.RequestManager;
9 | import com.socks.jiandan.utils.logger.LogLevel;
10 | import com.socks.jiandan.utils.logger.Logger;
11 | import com.socks.jiandan.view.imageloader.ImageLoadProxy;
12 |
13 |
14 | public class BaseFragment extends Fragment implements ConstantString {
15 |
16 | @Override
17 | public void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | if (BuildConfig.DEBUG) {
20 | Logger.init(getClass().getSimpleName()).setLogLevel(LogLevel.FULL).hideThreadInfo();
21 | } else {
22 | Logger.init(getClass().getSimpleName()).setLogLevel(LogLevel.NONE).hideThreadInfo();
23 | }
24 |
25 | }
26 |
27 | @Override
28 | public void onDestroy() {
29 | super.onDestroy();
30 | JDApplication.getRefWatcher(getActivity()).watch(this);
31 | RequestManager.cancelAll(this);
32 | ImageLoadProxy.getImageLoader().clearMemoryCache();
33 | }
34 |
35 | protected void executeRequest(Request request) {
36 | RequestManager.addRequest(request, this);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/socks/jiandan/base/ConstantString.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan.base;
2 |
3 | public interface ConstantString {
4 |
5 | String COMMENT_FAILED = "神秘力量导致评论失败 ⊙︿⊙";
6 | String VOTE_FAILED = "神秘力量导致投票失败 ⊙︿⊙";
7 | String LOAD_FAILED = "神秘力量导致加载失败 ⊙︿⊙";
8 | String SAVE_FAILED = "神秘力量导致保存失败 ⊙︿⊙";
9 | String LOAD_SHARE = "神秘力量导致分享失败 ⊙︿⊙";
10 |
11 | String INPUT_TOO_SHORT = "你的..太短..";
12 | String COPY_SUCCESS = "复制成功";
13 | String SAVE_SUCCESS = "保存成功";
14 | String SAVE_SMALL_SUCCESS = "保存缩略图成功";
15 | String VOTE_XX = "疼...轻点插";
16 | String VOTE_OO = "顶的好舒服~";
17 | String VOTE_REPEAT = "投过票了";
18 | String LOAD_NO_NETWORK = "无网络,当前为缓存数据";
19 | String FORBID_COMMENTS = "禁止评论";
20 | String NO_COMMENTS = "暂无评论";
21 |
22 | String DATA_FRESH_NEWS = "FreshNews";
23 | String DATA_POSITION = "position";
24 | String DATA_THREAD_ID = "thread_id";
25 | String DATA_THREAD_KEY = "thread_key";
26 | String DATA_IS_FROM_FRESH_NEWS = "is_from_fresh_news";
27 |
28 | String DATA_IMAGE_URL = "img_url";
29 | String DATA_IMAGE_ID = "img_id";
30 | String DATA_IMAGE_AUTHOR = "img_author";
31 | String DATA_IS_NEED_WEBVIEW = "is_need_webview";
32 |
33 | String DATA_IS_SIAMLL_PIC = "isSmallPic";
34 | String DATA_FILE_PATH = "file_path";
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/socks/jiandan/base/JDApplication.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan.base;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.graphics.Color;
6 |
7 | import com.socks.greendao.DaoMaster;
8 | import com.socks.greendao.DaoSession;
9 | import com.socks.jiandan.BuildConfig;
10 | import com.socks.jiandan.R;
11 | import com.socks.jiandan.cache.BaseCache;
12 | import com.socks.jiandan.utils.StrictModeUtil;
13 | import com.socks.jiandan.utils.logger.LogLevel;
14 | import com.socks.jiandan.utils.logger.Logger;
15 | import com.socks.jiandan.view.imageloader.ImageLoadProxy;
16 | import com.squareup.leakcanary.LeakCanary;
17 | import com.squareup.leakcanary.RefWatcher;
18 |
19 | public class JDApplication extends Application {
20 |
21 | public static int COLOR_OF_DIALOG = R.color.primary;
22 | public static int COLOR_OF_DIALOG_CONTENT = Color.WHITE;
23 |
24 | private static Context mContext;
25 | private static DaoMaster daoMaster;
26 | private static DaoSession daoSession;
27 |
28 | private RefWatcher refWatcher;
29 |
30 | @Override
31 | public void onCreate() {
32 | StrictModeUtil.init();
33 | super.onCreate();
34 | refWatcher = LeakCanary.install(this);
35 | mContext = this;
36 | ImageLoadProxy.initImageLoader(this);
37 |
38 | if (BuildConfig.DEBUG) {
39 | Logger.init().hideThreadInfo().setMethodCount(1).setLogLevel(LogLevel.FULL);
40 | }
41 | }
42 |
43 | public static Context getContext() {
44 | return mContext;
45 | }
46 |
47 | public static RefWatcher getRefWatcher(Context context) {
48 | JDApplication application = (JDApplication) context.getApplicationContext();
49 | return application.refWatcher;
50 | }
51 |
52 |
53 | public static DaoMaster getDaoMaster(Context context) {
54 | if (daoMaster == null) {
55 | DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context, BaseCache.DB_NAME, null);
56 | daoMaster = new DaoMaster(helper.getWritableDatabase());
57 | }
58 | return daoMaster;
59 | }
60 |
61 | public static DaoSession getDaoSession(Context context) {
62 | if (daoSession == null) {
63 | if (daoMaster == null) {
64 | daoMaster = getDaoMaster(context);
65 | }
66 | daoSession = daoMaster.newSession();
67 | }
68 | return daoSession;
69 | }
70 |
71 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/socks/jiandan/cache/BaseCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan.cache;
2 |
3 | import com.socks.greendao.DaoSession;
4 |
5 | import java.util.ArrayList;
6 |
7 | /**
8 | * Created by zhaokaiqiang on 15/5/12.
9 | */
10 | public abstract class BaseCache {
11 |
12 | public static final String DB_NAME = "jiandan-db";
13 |
14 | protected static DaoSession mDaoSession;
15 |
16 | public abstract void clearAllCache();
17 |
18 | public abstract ArrayList getCacheByPage(int page);
19 |
20 | public abstract void addResultCache(String result, int page);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/socks/jiandan/cache/FreshNewsCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan.cache;
2 |
3 | import android.content.Context;
4 |
5 | import com.socks.greendao.FreshNewsCacheDao;
6 | import com.socks.jiandan.base.JDApplication;
7 | import com.socks.jiandan.model.FreshNews;
8 |
9 | import org.json.JSONArray;
10 | import org.json.JSONException;
11 |
12 | import java.util.ArrayList;
13 |
14 | import de.greenrobot.dao.query.QueryBuilder;
15 |
16 | public class FreshNewsCache extends BaseCache {
17 |
18 | private static FreshNewsCache instance;
19 | private static FreshNewsCacheDao mFreshNewsCacheDao;
20 |
21 | private FreshNewsCache() {
22 | }
23 |
24 | public static FreshNewsCache getInstance(Context context) {
25 |
26 | if (instance == null) {
27 |
28 | synchronized (FreshNewsCache.class) {
29 | if (instance == null) {
30 | instance = new FreshNewsCache();
31 | }
32 | }
33 |
34 | mDaoSession = JDApplication.getDaoSession(context);
35 | mFreshNewsCacheDao = mDaoSession.getFreshNewsCacheDao();
36 | }
37 | return instance;
38 | }
39 |
40 | public void clearAllCache() {
41 | mFreshNewsCacheDao.deleteAll();
42 | }
43 |
44 | @Override
45 | public ArrayList getCacheByPage(int page) {
46 |
47 | QueryBuilder query = mFreshNewsCacheDao.queryBuilder().where(FreshNewsCacheDao
48 | .Properties.Page.eq("" + page));
49 |
50 | if (query.list().size() > 0) {
51 | try {
52 | return FreshNews.parseCache(new JSONArray(query.list().get(0)
53 | .getResult()));
54 | } catch (JSONException e) {
55 | e.printStackTrace();
56 | return new ArrayList<>();
57 | }
58 | } else {
59 | return new ArrayList<>();
60 | }
61 |
62 | }
63 |
64 | @Override
65 | public void addResultCache(String result, int page) {
66 |
67 | com.socks.greendao.FreshNewsCache freshNewsCache = new com.socks.greendao.FreshNewsCache();
68 | freshNewsCache.setResult(result);
69 | freshNewsCache.setPage(page);
70 | freshNewsCache.setTime(System.currentTimeMillis());
71 |
72 | mFreshNewsCacheDao.insert(freshNewsCache);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/socks/jiandan/cache/JokeCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan.cache;
2 |
3 | import android.content.Context;
4 |
5 | import com.google.gson.reflect.TypeToken;
6 | import com.socks.greendao.JokeCacheDao;
7 | import com.socks.jiandan.base.JDApplication;
8 | import com.socks.jiandan.model.Joke;
9 | import com.socks.jiandan.net.JSONParser;
10 |
11 | import java.util.ArrayList;
12 |
13 | import de.greenrobot.dao.query.QueryBuilder;
14 |
15 | public class JokeCache extends BaseCache {
16 |
17 | private static JokeCache instance;
18 | private static JokeCacheDao mJokeCacheDao;
19 |
20 | private JokeCache() {
21 | }
22 |
23 | public static JokeCache getInstance(Context context) {
24 |
25 | if (instance == null) {
26 |
27 | synchronized (JokeCache.class) {
28 | if (instance == null) {
29 | instance = new JokeCache();
30 | }
31 | }
32 |
33 | mDaoSession = JDApplication.getDaoSession(context);
34 | mJokeCacheDao = mDaoSession.getJokeCacheDao();
35 | }
36 | return instance;
37 | }
38 |
39 | public void clearAllCache() {
40 | mJokeCacheDao.deleteAll();
41 | }
42 |
43 |
44 | @Override
45 | public ArrayList getCacheByPage(int page) {
46 | QueryBuilder query = mJokeCacheDao.queryBuilder().where(JokeCacheDao.Properties.Page.eq("" + page));
47 |
48 | if (query.list().size() > 0) {
49 | return (ArrayList) JSONParser.toObject(query.list().get(0).getResult(),
50 | new TypeToken>() {
51 | }.getType());
52 | } else {
53 | return new ArrayList<>();
54 | }
55 |
56 | }
57 |
58 | @Override
59 | public void addResultCache(String result, int page) {
60 | com.socks.greendao.JokeCache jokeCache = new com.socks.greendao.JokeCache();
61 | jokeCache.setResult(result);
62 | jokeCache.setPage(page);
63 | jokeCache.setTime(System.currentTimeMillis());
64 |
65 | mJokeCacheDao.insert(jokeCache);
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/socks/jiandan/cache/PictureCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan.cache;
2 |
3 | import android.content.Context;
4 |
5 | import com.google.gson.reflect.TypeToken;
6 | import com.socks.greendao.PictureCacheDao;
7 | import com.socks.jiandan.base.JDApplication;
8 | import com.socks.jiandan.model.Picture;
9 | import com.socks.jiandan.net.JSONParser;
10 |
11 | import java.util.ArrayList;
12 |
13 | import de.greenrobot.dao.query.QueryBuilder;
14 |
15 | /**
16 | * Created by zhaokaiqiang on 15/5/11.
17 | */
18 | public class PictureCache extends BaseCache {
19 |
20 | private static PictureCache instance;
21 | private static PictureCacheDao mPictureCacheDao;
22 |
23 | private PictureCache() {
24 | }
25 |
26 | public static PictureCache getInstance(Context context) {
27 |
28 | if (instance == null) {
29 |
30 | synchronized (PictureCache.class) {
31 | if (instance == null) {
32 | instance = new PictureCache();
33 | }
34 | }
35 |
36 | mDaoSession = JDApplication.getDaoSession(context);
37 | mPictureCacheDao = mDaoSession.getPictureCacheDao();
38 | }
39 | return instance;
40 | }
41 |
42 | /**
43 | * 清楚全部缓存
44 | */
45 | public void clearAllCache() {
46 | mPictureCacheDao.deleteAll();
47 | }
48 |
49 | /**
50 | * 根据页码获取缓存数据
51 | *
52 | * @param page
53 | * @return
54 | */
55 | @Override
56 | public ArrayList getCacheByPage(int page) {
57 |
58 | QueryBuilder query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
59 | .Properties.Page.eq("" + page));
60 |
61 | if (query.list().size() > 0) {
62 | return (ArrayList) JSONParser.toObject(query.list().get(0).getResult(),
63 | new TypeToken>() {
64 | }.getType());
65 | } else {
66 | return new ArrayList();
67 | }
68 |
69 | }
70 |
71 | /**
72 | * 添加Jokes缓存
73 | *
74 | * @param result
75 | * @param page
76 | */
77 | @Override
78 | public void addResultCache(String result, int page) {
79 | com.socks.greendao.PictureCache pictureCache = new com.socks.greendao.PictureCache();
80 | pictureCache.setResult(result);
81 | pictureCache.setPage(page);
82 | pictureCache.setTime(System.currentTimeMillis());
83 |
84 | mPictureCacheDao.insert(pictureCache);
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/java/com/socks/jiandan/cache/SisterCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan.cache;
2 |
3 | import android.content.Context;
4 |
5 | import com.google.gson.reflect.TypeToken;
6 | import com.socks.greendao.SisterCacheDao;
7 | import com.socks.jiandan.base.JDApplication;
8 | import com.socks.jiandan.model.Picture;
9 | import com.socks.jiandan.net.JSONParser;
10 |
11 | import java.util.ArrayList;
12 |
13 | import de.greenrobot.dao.query.QueryBuilder;
14 |
15 | public class SisterCache extends BaseCache {
16 |
17 | private static SisterCache instance;
18 | private static SisterCacheDao mPictureCacheDao;
19 |
20 | private SisterCache() {
21 | }
22 |
23 | public static SisterCache getInstance(Context context) {
24 |
25 | if (instance == null) {
26 |
27 | synchronized (SisterCache.class) {
28 | if (instance == null) {
29 | instance = new SisterCache();
30 | }
31 | }
32 |
33 | mDaoSession = JDApplication.getDaoSession(context);
34 | mPictureCacheDao = mDaoSession.getSisterCacheDao();
35 | }
36 | return instance;
37 | }
38 |
39 | public void clearAllCache() {
40 | mPictureCacheDao.deleteAll();
41 | }
42 |
43 | @Override
44 | public ArrayList getCacheByPage(int page) {
45 |
46 | QueryBuilder query = mPictureCacheDao.queryBuilder().where(SisterCacheDao
47 | .Properties.Page.eq(Integer.toString(page)));
48 |
49 | if (query.list().size() > 0) {
50 | return (ArrayList) JSONParser.toObject(query.list().get(0).getResult(),
51 | new TypeToken>() {
52 | }.getType());
53 | } else {
54 | return new ArrayList<>();
55 | }
56 |
57 | }
58 |
59 | @Override
60 | public void addResultCache(String result, int page) {
61 | com.socks.greendao.SisterCache pictureCache = new com.socks.greendao.SisterCache();
62 | pictureCache.setResult(result);
63 | pictureCache.setPage(page);
64 | pictureCache.setTime(System.currentTimeMillis());
65 |
66 | mPictureCacheDao.insert(pictureCache);
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/socks/jiandan/cache/VideoCache.java:
--------------------------------------------------------------------------------
1 | package com.socks.jiandan.cache;
2 |
3 | import android.content.Context;
4 |
5 | import com.google.gson.reflect.TypeToken;
6 | import com.socks.greendao.VideoCacheDao;
7 | import com.socks.jiandan.base.JDApplication;
8 | import com.socks.jiandan.model.Video;
9 | import com.socks.jiandan.net.JSONParser;
10 |
11 | import java.util.ArrayList;
12 |
13 | import de.greenrobot.dao.query.QueryBuilder;
14 |
15 | public class VideoCache extends BaseCache {
16 |
17 | private static VideoCache instance;
18 | private static VideoCacheDao mVideoCacheDao;
19 |
20 | private VideoCache() {
21 | }
22 |
23 | public static VideoCache getInstance(Context context) {
24 |
25 | if (instance == null) {
26 |
27 | synchronized (VideoCache.class) {
28 | if (instance == null) {
29 | instance = new VideoCache();
30 | }
31 | }
32 |
33 | mDaoSession = JDApplication.getDaoSession(context);
34 | mVideoCacheDao = mDaoSession.getVideoCacheDao();
35 | }
36 | return instance;
37 | }
38 |
39 | public void clearAllCache() {
40 | mVideoCacheDao.deleteAll();
41 | }
42 |
43 | @Override
44 | public ArrayList