├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── isPlay.jks
├── proguard-rules.pro
├── release
│ ├── app-release.apk
│ ├── output.json
│ └── seven.apk
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── seven
│ │ └── seven
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── DINPro-Bold.otf
│ ├── java
│ │ └── com
│ │ │ └── seven
│ │ │ └── seven
│ │ │ ├── common
│ │ │ ├── Model
│ │ │ │ ├── BannerInfo.java
│ │ │ │ ├── BannerInfos.java
│ │ │ │ └── HttpErrorInfo.java
│ │ │ ├── base
│ │ │ │ ├── BaseModel.java
│ │ │ │ ├── BaseMvpActivity.java
│ │ │ │ ├── BaseMvpFragment.java
│ │ │ │ ├── HttpErrorReceiver.java
│ │ │ │ ├── IBaseModel.java
│ │ │ │ ├── IBaseView.java
│ │ │ │ ├── NetWorkStateReceiver.java
│ │ │ │ └── codereview
│ │ │ │ │ ├── BaseActivity.java
│ │ │ │ │ ├── BaseFragment.java
│ │ │ │ │ ├── BaseLazyFragment.java
│ │ │ │ │ ├── BasePresenter.java
│ │ │ │ │ ├── BasePresenterImpl.java
│ │ │ │ │ ├── BaseRetryWhen.java
│ │ │ │ │ └── BaseView.java
│ │ │ ├── event
│ │ │ │ ├── BaseEvent.java
│ │ │ │ ├── NetWorkChangeEvent.java
│ │ │ │ └── ReloginEvent.java
│ │ │ ├── network
│ │ │ │ ├── AddCookieInterceptor.java
│ │ │ │ ├── ApiException.java
│ │ │ │ ├── ApiRetrofit.java
│ │ │ │ ├── ApiService.java
│ │ │ │ ├── HttpCommonObserver.java
│ │ │ │ ├── HttpObservable.java
│ │ │ │ ├── HttpResultFunction.java
│ │ │ │ ├── HttpResultObserver.java
│ │ │ │ ├── HttpResultSubscriber.java
│ │ │ │ ├── NetworkUrl.java
│ │ │ │ ├── ResponseCustom.java
│ │ │ │ ├── RxLifeManager.java
│ │ │ │ ├── SaveCookieInterceptor.java
│ │ │ │ ├── ServerResultFunction.java
│ │ │ │ ├── ThreadSchedulersHelper.java
│ │ │ │ └── gank
│ │ │ │ │ ├── GankHttpObserver.java
│ │ │ │ │ ├── GankIoCustom.java
│ │ │ │ │ ├── GankIoObservable.java
│ │ │ │ │ └── GankResultObserver.java
│ │ │ ├── utils
│ │ │ │ ├── AppBarStateChangeListener.java
│ │ │ │ ├── AppManager.java
│ │ │ │ ├── Constans.java
│ │ │ │ ├── DataCleanManager.java
│ │ │ │ ├── DensityUtil.java
│ │ │ │ ├── FileUtils.java
│ │ │ │ ├── GlideUtils.java
│ │ │ │ ├── GsonTools.java
│ │ │ │ ├── HTMLScript.java
│ │ │ │ ├── ImageUtils.java
│ │ │ │ ├── LogUtils.java
│ │ │ │ ├── PermissionUtil.java
│ │ │ │ ├── PreferencesUtils.java
│ │ │ │ ├── RxManager.java
│ │ │ │ ├── RxTool.java
│ │ │ │ ├── ScaleTransformer.java
│ │ │ │ ├── ShareUtils.java
│ │ │ │ ├── StatusBarUtil.java
│ │ │ │ ├── TimeUtils.java
│ │ │ │ └── ToastUtils.java
│ │ │ └── view
│ │ │ │ ├── CustomCOnstantsView.java
│ │ │ │ ├── ErrorLayoutView.java
│ │ │ │ ├── FlowLayout.java
│ │ │ │ ├── GradientView.java
│ │ │ │ ├── HomeTitleView.java
│ │ │ │ ├── KeyLayout.java
│ │ │ │ ├── MarqueeView.java
│ │ │ │ ├── NestedScrollWebView.java
│ │ │ │ ├── NumberPlayTextView.java
│ │ │ │ ├── RollNumberTextView.java
│ │ │ │ ├── RollNumberView.java
│ │ │ │ ├── dialog
│ │ │ │ ├── ShareMenuPop.java
│ │ │ │ └── TakePhototpop.java
│ │ │ │ ├── progress
│ │ │ │ ├── AnimationUtils.java
│ │ │ │ ├── CircleSprite.java
│ │ │ │ ├── DoubleBounce.java
│ │ │ │ ├── Ease.java
│ │ │ │ ├── KeyFrameInterpolator.java
│ │ │ │ ├── ShapeSprite.java
│ │ │ │ ├── Sprite.java
│ │ │ │ ├── SpriteAnimatorBuilder.java
│ │ │ │ └── SpriteContainer.java
│ │ │ │ └── webview
│ │ │ │ ├── H5Control.java
│ │ │ │ ├── H5JSInterface.java
│ │ │ │ ├── H5ToAndroidData.java
│ │ │ │ ├── LookWebViewImg.java
│ │ │ │ └── SevenWebView.java
│ │ │ ├── gank
│ │ │ ├── GankFragment.java
│ │ │ ├── adapter
│ │ │ │ └── GankAdapter.java
│ │ │ ├── contract
│ │ │ │ └── GankContract.java
│ │ │ ├── events
│ │ │ │ └── GankEvents.java
│ │ │ ├── model
│ │ │ │ └── GankIoWelfareBean.java
│ │ │ └── presenter
│ │ │ │ └── GankPresenter.java
│ │ │ ├── home
│ │ │ ├── BaseHomeTitleBar.java
│ │ │ ├── BaseRecyclerFragment.java
│ │ │ ├── HomeFragment.java
│ │ │ ├── HomeNewsDetailActivity.java
│ │ │ ├── adapter
│ │ │ │ ├── BannerViewAdapter.java
│ │ │ │ ├── BaseLoadMoreAdapter.java
│ │ │ │ ├── HomeCommonAdapter.java
│ │ │ │ └── RvLoadMoreView.java
│ │ │ ├── bannerview
│ │ │ │ ├── BannerLayout.java
│ │ │ │ ├── RecyclerViewBannerBase.java
│ │ │ │ └── layoutmanager
│ │ │ │ │ ├── BannerLayoutManager.java
│ │ │ │ │ ├── CenterScrollListener.java
│ │ │ │ │ ├── CenterSnapHelper.java
│ │ │ │ │ └── OverFlyingLayoutManager.java
│ │ │ ├── contract
│ │ │ │ ├── BaseWebviewContract.java
│ │ │ │ └── HomeContract.java
│ │ │ ├── events
│ │ │ │ ├── BaseWebViewEvents.java
│ │ │ │ └── HomeEvents.java
│ │ │ ├── model
│ │ │ │ ├── HomeBannerInfos.java
│ │ │ │ ├── HomeNewsInfos.java
│ │ │ │ └── HomeToWebViewInfo.java
│ │ │ └── presenter
│ │ │ │ ├── BaseWebviewPresenter.java
│ │ │ │ └── HomePresenter.java
│ │ │ ├── login
│ │ │ ├── LoginActivity.java
│ │ │ ├── LoginContract.java
│ │ │ ├── LoginEvent.java
│ │ │ ├── LoginPresenter.java
│ │ │ ├── RegisterContract.java
│ │ │ ├── RegisterEvent.java
│ │ │ ├── RegisterInfo.java
│ │ │ ├── RegisterPresenter.java
│ │ │ └── RejisterActivity.java
│ │ │ ├── search
│ │ │ ├── LookImageActivity.java
│ │ │ ├── SearchAdapter.java
│ │ │ ├── SearchDetailActivity.java
│ │ │ ├── SearchFragment.java
│ │ │ ├── contract
│ │ │ │ ├── SearchContract.java
│ │ │ │ └── SearchKContract.java
│ │ │ ├── events
│ │ │ │ ├── HotTagEvent.java
│ │ │ │ └── SearchKEvent.java
│ │ │ ├── model
│ │ │ │ ├── HotTagInfos.java
│ │ │ │ ├── SearchListInfos.java
│ │ │ │ └── UsingURLinfos.java
│ │ │ └── presenter
│ │ │ │ ├── HotTagPresenter.java
│ │ │ │ └── SearchKPresenter.java
│ │ │ ├── ui
│ │ │ ├── MainActivity.java
│ │ │ ├── MyApplication.java
│ │ │ ├── MyPagerAdapter.java
│ │ │ ├── SplashActivity.java
│ │ │ ├── TestActivity.java
│ │ │ ├── TestAdapter.java
│ │ │ └── base
│ │ │ │ ├── activity
│ │ │ │ ├── ConstantsLayout.java
│ │ │ │ └── ViewTestActivity.java
│ │ │ │ └── fragment
│ │ │ │ ├── EFragment.java
│ │ │ │ ├── NoSlideViewPager.java
│ │ │ │ └── TabItemInfo.java
│ │ │ └── user
│ │ │ ├── CollectListActivity.java
│ │ │ ├── RenderscriptUtils.java
│ │ │ ├── UserInfoFragment.java
│ │ │ ├── adapter
│ │ │ └── CollectAdapter.java
│ │ │ ├── contract
│ │ │ ├── CollectContract.java
│ │ │ └── UserInfoContract.java
│ │ │ ├── model
│ │ │ ├── CollectInfo.java
│ │ │ └── CollectListInfos.java
│ │ │ ├── presenter
│ │ │ ├── CollectPresenter.java
│ │ │ └── UserInfoPresenter.java
│ │ │ ├── userevent
│ │ │ ├── CollectEvent.java
│ │ │ └── UserInfoEvent.java
│ │ │ └── view
│ │ │ ├── CanleLoginDialog.java
│ │ │ ├── DeleteCacheDialog.java
│ │ │ ├── HeadImgView.java
│ │ │ └── UserInfoItemView.java
│ └── res
│ │ ├── anim
│ │ ├── activity_finish_trans_in.xml
│ │ ├── activity_finish_trans_out.xml
│ │ ├── activity_start_zoom_in.xml
│ │ └── activity_start_zoom_out.xml
│ │ ├── drawable-hdpi
│ │ └── loading_android_1.jpg
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xxhdpi
│ │ ├── error.jpg
│ │ ├── ic_arrow_back_white.png
│ │ ├── ic_check_white_48dp.png
│ │ ├── ic_clear_white_48dp.png
│ │ ├── ic_error_logo.png
│ │ ├── ic_error_outline_white_48dp.png
│ │ ├── ic_heart_follow.png
│ │ ├── ic_heart_un_follow.png
│ │ ├── ic_home_selector.png
│ │ ├── ic_home_un_selector.png
│ │ ├── ic_hot_search.png
│ │ ├── ic_info_outline_white_48dp.png
│ │ ├── ic_language_choose.png
│ │ ├── ic_menu_black.png
│ │ ├── ic_person_customer_service.png
│ │ ├── ic_person_help.png
│ │ ├── ic_person_integral.png
│ │ ├── ic_person_right.png
│ │ ├── ic_person_us.png
│ │ ├── ic_return_black.png
│ │ ├── ic_search.png
│ │ ├── ic_share_app.png
│ │ ├── icon_weixin.png
│ │ ├── icon_weixin_pengyouquan.png
│ │ ├── my_selector.png
│ │ ├── my_un_selector.png
│ │ ├── seven_logo.png
│ │ ├── tab_fuli.png
│ │ ├── tab_search.png
│ │ ├── tab_selector_fuli.png
│ │ ├── tab_selector_search.png
│ │ ├── timgs.jpg
│ │ └── toast_frame.9.png
│ │ ├── drawable
│ │ ├── bg_menu.9.png
│ │ ├── btn_dialog_left_normal.xml
│ │ ├── btn_dialog_left_pressed.xml
│ │ ├── btn_dialog_left_selector.xml
│ │ ├── dialog_background.xml
│ │ ├── fuli_button_selector.xml
│ │ ├── home_button_selector.xml
│ │ ├── home_toolbar_bg.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── item_touch_bg.xml
│ │ ├── my_button_selector.xml
│ │ ├── red_background_shape.xml
│ │ ├── refresh_button_drawable.xml
│ │ ├── refresh_normal_shape.xml
│ │ ├── refresh_press_shape.xml
│ │ ├── search_background.xml
│ │ ├── search_button_selector.xml
│ │ ├── tab_item_name_selector.xml
│ │ ├── test.xml
│ │ ├── text_background.xml
│ │ ├── web_progress_bar_bg.xml
│ │ └── webview_top_progress.xml
│ │ ├── layout
│ │ ├── activity_collect_list.xml
│ │ ├── activity_home_news_detail.xml
│ │ ├── activity_login.xml
│ │ ├── activity_look_image.xml
│ │ ├── activity_main.xml
│ │ ├── activity_register.xml
│ │ ├── activity_search_detail.xml
│ │ ├── activity_splash.xml
│ │ ├── activity_view.xml
│ │ ├── banner_item.xml
│ │ ├── base_home_title.xml
│ │ ├── dialog_cancle.xml
│ │ ├── dialog_delete.xml
│ │ ├── error_layout.xml
│ │ ├── fragment_gank.xml
│ │ ├── fragment_home.xml
│ │ ├── fragment_home_me.xml
│ │ ├── fragment_search.xml
│ │ ├── fragment_user_info.xml
│ │ ├── home_title.xml
│ │ ├── layout_constants.xml
│ │ ├── layout_recycler_loadmore.xml
│ │ ├── pop_share_menu.xml
│ │ ├── pop_take_photo.xml
│ │ ├── recycler_head_view.xml
│ │ ├── recycler_item_banner.xml
│ │ ├── recycler_item_collect.xml
│ │ ├── recycler_item_gank.xml
│ │ ├── recycler_item_home_news.xml
│ │ ├── recycler_item_search.xml
│ │ ├── tab_item_view.xml
│ │ ├── toast_layout.xml
│ │ └── user_info_item_view.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_round.png
│ │ └── seven_logo.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── arrays.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── seven
│ └── seven
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── keystore.properties
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seven123456/seven_develop/e28549c65fa5f82c3691c041fe0f06e837f014fd/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # seven_develop
2 | ## 代码结构:mvp+retrofit+rxjava+eventbus
3 | ## 功能模块分为首页、搜索、干货、个人四个模块
4 | ## 效果图(七牛云在审核,暂时上传不了gif):
5 | 登录界面:
6 | 首页: 
7 | 搜索: 
8 | 干货: 
9 | 个人: 
10 | # 项目使用到的api: #
11 | 感谢鸿洋大神的www.wanandroid.com提供的api
12 | 还有干货集中云的api:http://gank.io/api
13 |
14 | # 感兴趣的朋友可以[下载demo](https://fir.im/mche1 "下载demo")体验一下,欢迎各位star 下载 #
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/isPlay.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seven123456/seven_develop/e28549c65fa5f82c3691c041fe0f06e837f014fd/app/isPlay.jks
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/release/app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seven123456/seven_develop/e28549c65fa5f82c3691c041fe0f06e837f014fd/app/release/app-release.apk
--------------------------------------------------------------------------------
/app/release/output.json:
--------------------------------------------------------------------------------
1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"com.seven.seven","split":"","minSdkVersion":"19"}}]
--------------------------------------------------------------------------------
/app/release/seven.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seven123456/seven_develop/e28549c65fa5f82c3691c041fe0f06e837f014fd/app/release/seven.apk
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/seven/seven/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.seven.seven", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
23 |
24 |
27 |
28 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/assets/DINPro-Bold.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seven123456/seven_develop/e28549c65fa5f82c3691c041fe0f06e837f014fd/app/src/main/assets/DINPro-Bold.otf
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/Model/BannerInfo.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.Model;
2 |
3 | /**
4 | * Created on 2018-03-19.
5 | * author:seven
6 | * email:seven2016s@163.com
7 | */
8 |
9 | class BannerInfo {
10 | public String desc;
11 | public int id;
12 | public String imagePath;
13 | public int isVisible;
14 | public int order;
15 | public String title;
16 | public int type;
17 | public String url;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/Model/HttpErrorInfo.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.Model;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created on 2018-03-26.
7 | * author:seven
8 | * email:seven2016s@163.com
9 | */
10 |
11 | public class HttpErrorInfo implements Serializable {
12 | private String msg;
13 |
14 | public HttpErrorInfo(String msg) {
15 | this.msg = msg;
16 | }
17 |
18 | public String getMsg() {
19 | return msg;
20 | }
21 |
22 | public void setMsg(String msg) {
23 | this.msg = msg;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/BaseModel.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base;
2 |
3 | /**
4 | * Created on 2018-01-05.
5 | * author:seven
6 | * email:seven2016s@163.com
7 | */
8 |
9 | public abstract class BaseModel {
10 | public BaseModel() {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/BaseMvpActivity.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.seven.seven.common.base.codereview.BaseActivity;
6 | import com.seven.seven.common.base.codereview.BasePresenter;
7 | import com.seven.seven.common.utils.AppManager;
8 | import com.seven.seven.common.utils.ToastUtils;
9 |
10 | /**
11 | * Created on 2018-01-05.
12 | * author:seven
13 | * email:seven2016s@163.com
14 | */
15 |
16 | public abstract class BaseMvpActivity
17 | extends BaseActivity implements IBaseView {
18 | /*
19 | * 这里还是属于基类,具体实例化由子类去实现
20 | * */
21 | protected P mPresenter;
22 | protected M mModel;
23 |
24 | @Override
25 | protected void init(Bundle savedInstanceState) {
26 | super.init(savedInstanceState);
27 | }
28 |
29 | /*
30 | * 通过继承关系,p层去持有v层对象
31 | * 然后再通过p层去持有M层对象
32 | * 最后通过P持有 m层和v层对象,这里面存在一个层级关系
33 | * */
34 | @Override
35 | protected void initData() {
36 | /* mPresenter = (P) initPresenter();
37 | if (mPresenter != null) {
38 | // mModel = (M) mPresenter.getModel();
39 | if (mModel != null) {
40 | // mPresenter.attachMV(mModel, this);
41 | }
42 | }*/
43 | }
44 |
45 | /*
46 | * 通过p层里面的方法来进行解绑v 和M 层的持有关系
47 | * */
48 | /* @Override
49 | protected void onDestroy() {
50 | super.onDestroy();
51 | if (mPresenter != null) {
52 | mPresenter.detachMV();
53 | }
54 | }
55 | */
56 | /* @Override
57 | public void showToast(String msg) {
58 | ToastUtils.showToast(msg);
59 | }
60 |
61 | @Override
62 | public void back() {
63 | AppManager.getAppManager().finishActivity(this);
64 | }*/
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/BaseMvpFragment.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.seven.seven.common.base.codereview.BaseFragment;
7 | import com.seven.seven.common.base.codereview.BasePresenter;
8 |
9 | /**
10 | * Created on 2018-03-31.
11 | * author:seven
12 | * email:seven2016s@163.com
13 | */
14 |
15 | public abstract class BaseMvpFragment
extends BaseFragment implements IBaseView {
16 | @Override
17 | protected void initView() {
18 | super.initView();
19 | }
20 |
21 | @Override
22 | public void startNewActivityForResult(@NonNull Class> clz, Bundle bundle, int requestCode) {
23 |
24 | }
25 |
26 | @Override
27 | public void startNewActivity(@NonNull Class> clz) {
28 |
29 | }
30 |
31 | @Override
32 | public void startNewActivity(@NonNull Class> clz, Bundle bundle) {
33 |
34 | }
35 |
36 | /* @Override
37 | public void showToast(String msg) {
38 |
39 | }
40 |
41 | @Override
42 | public void back() {
43 |
44 | }*/
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/HttpErrorReceiver.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.net.ConnectivityManager;
7 | import android.net.Network;
8 | import android.net.NetworkInfo;
9 | import android.widget.Toast;
10 |
11 | import com.seven.seven.common.event.NetWorkChangeEvent;
12 | import com.seven.seven.common.utils.Constans;
13 |
14 | import org.greenrobot.eventbus.EventBus;
15 |
16 | /**
17 | * Created by Carson_Ho on 16/10/31.
18 | */
19 | public class HttpErrorReceiver extends BroadcastReceiver {
20 | @Override
21 | public void onReceive(Context context, Intent intent) {
22 | String action = intent.getAction();
23 | if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
24 | //获得ConnectivityManager对象
25 | ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
26 | //获取ConnectivityManager对象对应的NetworkInfo对象
27 | NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
28 | if (networkInfo != null && networkInfo.isAvailable()) {
29 | EventBus.getDefault().post(new NetWorkChangeEvent(Constans.NET_WORK_AVAILABLE));
30 | } else {
31 | EventBus.getDefault().post(new NetWorkChangeEvent(Constans.NET_WORK_DISABLED));
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/IBaseModel.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base;
2 |
3 | /**
4 | * Created on 2018-03-15.
5 | * author:seven
6 | * email:seven2016s@163.com
7 | */
8 |
9 | public interface IBaseModel {
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/IBaseView.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.seven.seven.common.base.codereview.BaseView;
7 |
8 | /**
9 | * Created on 2018-03-15.
10 | * author:seven
11 | * email:seven2016s@163.com
12 | */
13 |
14 | public interface IBaseView extends BaseView {
15 | /**
16 | * 跳往新的Activity
17 | *
18 | * @param clz 要跳往的Activity
19 | */
20 | void startNewActivity(@NonNull Class> clz);
21 |
22 | /**
23 | * 跳往新的Activity
24 | *
25 | * @param clz 要跳往的Activity
26 | * @param bundle 携带的bundle数据
27 | */
28 | void startNewActivity(@NonNull Class> clz, Bundle bundle);
29 |
30 | /**
31 | * 跳往新的Activity
32 | * @param clz 要跳转的Activity
33 | * @param bundle bundel数据
34 | * @param requestCode requestCode
35 | */
36 | void startNewActivityForResult(@NonNull Class> clz, Bundle bundle, int requestCode);
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/codereview/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base.codereview;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.seven.seven.R;
12 | import com.seven.seven.common.utils.ToastUtils;
13 |
14 | /**
15 | * Created on 2018-01-05.
16 | * author:seven
17 | * email:seven2016s@163.com
18 | */
19 |
20 | public abstract class BaseFragment extends Fragment implements View.OnClickListener {
21 | public View rootView;
22 |
23 | @Override
24 | public void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | }
27 |
28 | @Nullable
29 | @Override
30 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
31 | if (rootView == null) {
32 | rootView = inflater.inflate(getLayoutId(), container, false);
33 | }
34 |
35 | initView();
36 | setLisenter();
37 | initData();
38 | return rootView;
39 | }
40 |
41 |
42 |
43 | // protected abstract void initView(View rootView, Bundle savedInstanceState);
44 |
45 | /*
46 | * 带图片的toast
47 | * */
48 | public void showSuccessToast(String msg) {
49 | ToastUtils.success(msg);
50 | }
51 |
52 | /*
53 | * error的toast
54 | * */
55 | public void showErrorToast(String msg) {
56 | ToastUtils.error(msg);
57 | }
58 |
59 | protected abstract int getLayoutId();
60 |
61 | protected void initView() {
62 |
63 | }
64 |
65 |
66 | protected abstract void initData();
67 |
68 | protected abstract void setLisenter();
69 |
70 | protected abstract void widgetClick(View v);
71 |
72 | @Override
73 | public void onClick(View v) {
74 | widgetClick(v);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/codereview/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base.codereview;
2 |
3 | /**
4 | * Created on 2018-01-05.
5 | * author:seven
6 | * email:seven2016s@163.com
7 | */
8 |
9 | public interface BasePresenter {
10 | void attachView(V view);
11 | void attachActivity(T activity);
12 | void detachView();
13 | void detachActivity();
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/codereview/BasePresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base.codereview;
2 |
3 | import com.seven.seven.common.network.ApiRetrofit;
4 | import com.seven.seven.common.network.ApiService;
5 |
6 | import java.lang.ref.Reference;
7 | import java.lang.ref.WeakReference;
8 |
9 | /**
10 | * Created by seven
11 | * on 2018/5/17
12 | * email:seven2016s@163.com
13 | */
14 |
15 | public class BasePresenterImpl implements BasePresenter {
16 | public final ApiService apiRetrofit;
17 | private Reference viewReference;
18 | private Reference activityReference;
19 | private V mView;
20 | private T mActivity;
21 |
22 | public BasePresenterImpl(V view, T activity) {
23 | attachActivity(activity);
24 | attachView(view);
25 | apiRetrofit = ApiRetrofit.getApiRetrofit().getApiServis();
26 | }
27 |
28 | @Override
29 | public void attachView(V view) {
30 | viewReference = new WeakReference(view);
31 | mView = viewReference.get();
32 | }
33 |
34 | @Override
35 | public void attachActivity(T activity) {
36 | activityReference = new WeakReference(activity);
37 | mActivity = activityReference.get();
38 | }
39 |
40 | @Override
41 | public void detachView() {
42 | if (isViewAttach()) {
43 | viewReference.clear();
44 | viewReference = null;
45 | }
46 | }
47 |
48 | @Override
49 | public void detachActivity() {
50 | if (isActivityAttach()) {
51 | activityReference.clear();
52 | activityReference = null;
53 | }
54 | }
55 |
56 | /*
57 | * view 是否关联
58 | * */
59 | public boolean isViewAttach() {
60 | return viewReference != null && viewReference.get() != null;
61 | }
62 |
63 | /*
64 | * activity是否关联
65 | * */
66 | public boolean isActivityAttach() {
67 | return activityReference != null && activityReference.get() != null;
68 | }
69 |
70 | /*
71 | * 获取view
72 | *
73 | * */
74 | public V getView() {
75 | return viewReference == null ? null : viewReference.get();
76 | }
77 |
78 | /*
79 | * 获取activity
80 | * */
81 | public T getActivity() {
82 | return activityReference == null ? null : activityReference.get();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/codereview/BaseRetryWhen.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base.codereview;
2 |
3 |
4 | import android.util.Log;
5 |
6 | import java.util.concurrent.TimeUnit;
7 |
8 | import io.reactivex.Observable;
9 | import io.reactivex.ObservableSource;
10 | import io.reactivex.functions.Function;
11 |
12 | /**
13 | * Created on 2018-05-25.
14 | * author:seven
15 | * email:seven2016s@163.com
16 | */
17 |
18 | public class BaseRetryWhen implements Function, Observable>> {
19 |
20 | private final int maxRetries;//请求次数
21 | private final int retryDelayMillis;//请求间隔时间
22 | private int retryCount;
23 |
24 | public BaseRetryWhen(int maxRetries, int retryDelayMillis) {
25 | this.maxRetries = maxRetries;
26 | this.retryDelayMillis = retryDelayMillis;
27 | }
28 |
29 | @Override
30 | public Observable> apply(Observable extends Throwable> observable) throws Exception {
31 |
32 | return observable.flatMap(new Function>() {
33 | @Override
34 | public ObservableSource> apply(Throwable throwable) throws Exception {
35 |
36 | Log.d("重新请求", "1111");
37 | if (++retryCount <= maxRetries) {
38 | return Observable.timer(retryDelayMillis, TimeUnit.MILLISECONDS);
39 | }
40 | return Observable.error(throwable);
41 | }
42 | });
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/base/codereview/BaseView.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.base.codereview;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | /**
6 | * Created on 2018-01-05.
7 | * author:seven
8 | * email:seven2016s@163.com
9 | */
10 |
11 | public interface BaseView {
12 | /*
13 | *//**
14 | * 显示toast消息
15 | *
16 | * @param msg 要显示的toast消息字符串
17 | *//*
18 | void showToast(String msg);
19 |
20 | *//**
21 | * 回退
22 | *//*
23 | void back();*/
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/event/BaseEvent.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.event;
2 |
3 | /**
4 | * Created on 2018-03-26.
5 | * author:seven
6 | * email:seven2016s@163.com
7 | */
8 |
9 | public class BaseEvent {
10 | private int what;
11 | private T data;
12 |
13 | public BaseEvent(){}
14 |
15 | public BaseEvent(int what) {
16 | this(what, null);
17 | }
18 |
19 | public BaseEvent(int what, T data) {
20 | this.what = what;
21 | this.data = data;
22 | }
23 |
24 | public int getWhat() {
25 | return what;
26 | }
27 |
28 | public void setWhat(int what) {
29 | this.what = what;
30 | }
31 |
32 | public Object getData() {
33 | return data;
34 | }
35 |
36 | public void setData(T data) {
37 | this.data = data;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/event/NetWorkChangeEvent.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.event;
2 |
3 | /**
4 | * Created on 2018-03-26.
5 | * author:seven
6 | * email:seven2016s@163.com
7 | */
8 |
9 | public class NetWorkChangeEvent extends BaseEvent {
10 |
11 | public NetWorkChangeEvent() {
12 | }
13 |
14 | public NetWorkChangeEvent(int what) {
15 | super(what);
16 | }
17 |
18 | public NetWorkChangeEvent(int what, Object data) {
19 | super(what, data);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/event/ReloginEvent.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.event;
2 |
3 | /**
4 | * Created on 2018-05-30.
5 | * author:seven
6 | * email:seven2016s@163.com
7 | */
8 |
9 | public class ReloginEvent extends BaseEvent {
10 | public ReloginEvent() {
11 | }
12 |
13 | public ReloginEvent(int what) {
14 | super(what);
15 | }
16 |
17 | public ReloginEvent(int what, Object data) {
18 | super(what, data);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/AddCookieInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.text.TextUtils;
6 |
7 | import com.seven.seven.common.utils.Constans;
8 | import com.seven.seven.common.utils.PreferencesUtils;
9 | import com.seven.seven.ui.MyApplication;
10 |
11 | import java.io.IOException;
12 |
13 | import okhttp3.Interceptor;
14 | import okhttp3.Request;
15 | import okhttp3.Response;
16 |
17 | import static com.seven.seven.common.utils.Constans.COOKIE_PREF;
18 |
19 | /**
20 | * Created on 2018-05-26.
21 | * author:seven
22 | * email:seven2016s@163.com
23 | */
24 |
25 | public class AddCookieInterceptor implements Interceptor {
26 | public static String PREFERENCE_NAME = "Config";
27 |
28 | /* private Context mContext;
29 |
30 | public AddCookieInterceptor(Context context) {
31 | this.mContext = context;
32 | }
33 | */
34 | @Override
35 | public Response intercept(Chain chain) throws IOException {
36 | Request request = chain.request();
37 | Request.Builder builder = request.newBuilder();
38 | String cookie = getCookie(request.url().toString(), request.url().host());
39 | if (!TextUtils.isEmpty(cookie)) {
40 | builder.addHeader("cookie", cookie);
41 | }
42 | return chain.proceed(builder.build());
43 | }
44 |
45 | private String getCookie(String url, String host) {
46 | SharedPreferences sp = MyApplication.getContext().getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
47 | /*if (!TextUtils.isEmpty(url) && sp.contains(url) && !TextUtils.isEmpty(sp.getString(url, ""))) {
48 | return sp.getString(url, "");
49 | }
50 | if (!TextUtils.isEmpty(host) && sp.contains(host) && !TextUtils.isEmpty(sp.getString(host, ""))) {
51 | return sp.getString(host, "");
52 | }*/
53 | return sp.getString(Constans.COOKIE_PREF, null);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/ApiException.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | /**
4 | * Created on 2018-03-26.
5 | * author:seven
6 | * email:seven2016s@163.com
7 | */
8 |
9 | public class ApiException extends Exception {
10 | /**
11 | * 错误码
12 | */
13 | private int errorCode;
14 | /**
15 | * 错误信息
16 | */
17 | private String errorMsg;
18 |
19 | public Object getData() {
20 | return data;
21 | }
22 |
23 | public void setData(Object data) {
24 | this.data = data;
25 | }
26 |
27 | private Object data;
28 | public ApiException(Throwable throwable, int code) {
29 | super(throwable);
30 | this.errorCode = code;
31 | }
32 |
33 | public ApiException(int code, String msg) {
34 | this.errorCode = code;
35 | this.errorMsg = msg;
36 | }
37 |
38 | public int getCode() {
39 | return errorCode;
40 | }
41 |
42 | public void setCode(int code) {
43 | this.errorCode = code;
44 | }
45 |
46 | public String getMsg() {
47 | return errorMsg;
48 | }
49 |
50 | public void setMsg(String msg) {
51 | this.errorMsg = msg;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/HttpCommonObserver.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | import android.util.Log;
4 |
5 | import java.net.UnknownServiceException;
6 |
7 | import io.reactivex.Observer;
8 | import io.reactivex.disposables.Disposable;
9 |
10 | /**
11 | * Created on 2018-03-20.
12 | * author:seven
13 | * email:seven2016s@163.com
14 | */
15 |
16 | public abstract class HttpCommonObserver implements Observer {
17 | private boolean flag = false;//是否切断上下游的事件传递
18 | public static final int UN_KNOWN_ERROR = 1000;//未知错误
19 |
20 | public HttpCommonObserver() {
21 | }
22 |
23 | public HttpCommonObserver(boolean isLink) {
24 | this.flag = isLink;
25 | }
26 |
27 | @Override
28 | public void onSubscribe(Disposable d) {
29 | this.onStart(d);
30 | if (flag) {
31 | RxLifeManager.getRxLifeManager().setCompositeDisposableOnStop(d);
32 | } else {
33 | RxLifeManager.getRxLifeManager().setCompositeDisposableOnDestroy(d);
34 | }
35 | }
36 |
37 | protected abstract void onStart(Disposable d);
38 |
39 | protected abstract void _onNext(T t);
40 |
41 | // protected abstract void _onError(ApiException e);
42 | protected abstract void _onError(ApiException e);
43 |
44 | /*
45 | * t==response
46 | * */
47 | @Override
48 | public void onNext(T t) {
49 | if (t != null) {
50 | this._onNext(t);
51 | }
52 |
53 | }
54 |
55 | @Override
56 | public void onError(Throwable e) {
57 | if (e instanceof ApiException || e instanceof UnknownServiceException) {
58 | _onError((ApiException) e);
59 | Log.e("onerror", "错误编码===" + ((ApiException) e).getCode() + "错误信息===" + ((ApiException) e).getMsg());
60 | } else {
61 | this._onError(new ApiException(e, UN_KNOWN_ERROR));
62 | }
63 | // this._onError(e);
64 | }
65 |
66 | @Override
67 | public void onComplete() {
68 |
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/HttpObservable.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | import io.reactivex.Observable;
4 | import io.reactivex.Observer;
5 | import io.reactivex.android.schedulers.AndroidSchedulers;
6 | import io.reactivex.schedulers.Schedulers;
7 |
8 | /**
9 | * Created by seven
10 | * on 2018/5/17
11 | * email:seven2016s@163.com
12 | */
13 |
14 | public class HttpObservable {
15 | public static Observable getObservable(Observable> customObservable) {
16 | Observable observable = customObservable
17 | .map(new ServerResultFunction())
18 | .onErrorResumeNext(new HttpResultFunction())
19 | .subscribeOn(Schedulers.io())
20 | .observeOn(AndroidSchedulers.mainThread());
21 | return observable;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/HttpResultFunction.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | import android.util.Log;
4 |
5 | import io.reactivex.Observable;
6 | import io.reactivex.functions.Function;
7 |
8 | /**
9 | * @author seven
10 | * @date 2017/10/31
11 | */
12 |
13 | public class HttpResultFunction implements Function> {
14 | @Override
15 | public Observable apply(Throwable throwable) throws Exception {
16 | //打印具体错误
17 | Log.d("HttpResultFunction:", throwable.getMessage());
18 | return Observable.error(throwable);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/HttpResultObserver.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | import com.seven.seven.common.event.ReloginEvent;
4 | import com.seven.seven.common.utils.Constans;
5 | import com.seven.seven.user.userevent.UserInfoEvent;
6 |
7 | import org.greenrobot.eventbus.EventBus;
8 |
9 | import io.reactivex.disposables.Disposable;
10 |
11 | /**
12 | * Created on 2018-03-20.
13 | * author:seven
14 | * email:seven2016s@163.com
15 | */
16 |
17 | public abstract class HttpResultObserver extends HttpCommonObserver {
18 |
19 | protected abstract void onLoading(Disposable d);
20 |
21 | protected abstract void onSuccess(T o);
22 |
23 | protected abstract void onFail(ApiException e);
24 |
25 | @Override
26 | protected void onStart(Disposable d) {
27 | onLoading(d);
28 | }
29 |
30 | @Override
31 | protected void _onNext(T responseCustom) {
32 | if (responseCustom.getErrorCode() < 0) {
33 | if (responseCustom.getErrorMsg().contains("登录")) {
34 | EventBus.getDefault().post(new ReloginEvent(Constans.RELOGIN));
35 | // EventBus.getDefault().post(new UserInfoEvent(Constans.RELOGIN));
36 | } else {
37 | onFail(new ApiException(responseCustom.getErrorCode(), responseCustom.getErrorMsg()));
38 | }
39 | } else {
40 | onSuccess(responseCustom);
41 | }
42 | }
43 |
44 | @Override
45 | protected void _onError(ApiException error) {
46 | onFail(error);
47 | // Log.e("网络处理异常", error.getMessage());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/HttpResultSubscriber.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 |
4 | import android.util.Log;
5 |
6 | import org.reactivestreams.Subscriber;
7 | import org.reactivestreams.Subscription;
8 |
9 | import io.reactivex.disposables.Disposable;
10 |
11 | import static com.seven.seven.common.network.HttpCommonObserver.UN_KNOWN_ERROR;
12 |
13 | /**
14 | * Created on 2018-03-20.
15 | * author:seven
16 | * email:seven2016s@163.com
17 | */
18 |
19 | public abstract class HttpResultSubscriber implements Subscriber {
20 | protected abstract void onLoading(Disposable d);
21 |
22 | protected abstract void onSuccess(T o);
23 |
24 | protected abstract void onFail(ApiException e);
25 |
26 |
27 | @Override
28 | public void onNext(T tResponseCustom) {
29 | onSuccess(tResponseCustom);
30 | }
31 |
32 | @Override
33 | public void onError(Throwable e) {
34 | if (e instanceof ApiException) {
35 | onFail((ApiException) e);
36 | Log.e("onerror", "错误编码===" + ((ApiException) e).getCode() + "错误信息===" + ((ApiException) e).getMsg());
37 | } else {
38 | this.onFail(new ApiException(e, UN_KNOWN_ERROR));
39 | }
40 | }
41 |
42 | @Override
43 | public void onComplete() {
44 |
45 | }
46 |
47 | @Override
48 | public void onSubscribe(Subscription s) {
49 | s.request(Long.MAX_VALUE);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/NetworkUrl.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | import com.seven.seven.ui.MyApplication;
4 |
5 | /**
6 | * Created on 2018-03-20.
7 | * author:seven
8 | * email:seven2016s@163.com
9 | */
10 |
11 | public class NetworkUrl {
12 | public static final String ANDROID_TEST_SERVICE ="http://www.wanandroid.com/";
13 | public static final String ANDROID_BAIDU_SERVICE ="http://gank.io";
14 |
15 | public static String getNetWorkName(){
16 | if (MyApplication.getIsDebug()){
17 | return ANDROID_TEST_SERVICE;
18 | }else {
19 | return ANDROID_BAIDU_SERVICE;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/ResponseCustom.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created on 2018-03-20.
7 | * author:seven
8 | * email:seven2016s@163.com
9 | */
10 |
11 | public class ResponseCustom implements Serializable {
12 |
13 |
14 | private int errorCode;
15 | private String errorMsg;
16 | private T data;
17 |
18 | /**
19 | * 是否成功(这里约定200)
20 | *
21 | * @return
22 | */
23 | public boolean isSuccess() {
24 | return errorCode >= 0 ? true : false;
25 | }
26 |
27 | public int getErrorCode() {
28 | return errorCode;
29 | }
30 |
31 | public void setErrorCode(int errorCode) {
32 | this.errorCode = errorCode;
33 | }
34 |
35 |
36 | public String getErrorMsg() {
37 | return errorMsg;
38 | }
39 |
40 | public void setErrorMsg(String errorMsg) {
41 | this.errorMsg = errorMsg;
42 | }
43 |
44 | public T getData() {
45 | return data;
46 | }
47 |
48 | public void setData(T data) {
49 | this.data = data;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/RxLifeManager.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | import io.reactivex.annotations.NonNull;
4 | import io.reactivex.disposables.CompositeDisposable;
5 | import io.reactivex.disposables.Disposable;
6 |
7 | /**
8 | * Created on 2018-03-20.
9 | * author:seven
10 | * email:seven2016s@163.com
11 | *
12 | * rxlifemanager用于切断上游与下游直接的联系,
13 | * 也就是说我只要执行了disposable,上游事件将无法传递给下游去接受 订阅关系结束
14 | * 集中处理在baseactivity里面就足够了,如果某一个页面需要就单独处理
15 | * 有没有效阻止rx泄露我也不知道 ,在这里统一做disposbale是为了封装observer处理onstart()
16 | */
17 | public class RxLifeManager {
18 |
19 | private static volatile RxLifeManager rxLifeManager;
20 | private CompositeDisposable compositeDisposableOnStop = new CompositeDisposable();//在页面onstop的时候切断
21 | private CompositeDisposable compositeDisposableOnDestroy = new CompositeDisposable();//在页面ondestroy时候切断
22 |
23 | public RxLifeManager() {
24 | }
25 |
26 | public static RxLifeManager getRxLifeManager() {
27 | if (rxLifeManager == null) {
28 | synchronized (RxLifeManager.class) {
29 | if (rxLifeManager == null) {
30 | rxLifeManager = new RxLifeManager();
31 | }
32 | }
33 | }
34 | return rxLifeManager;
35 | }
36 |
37 | public void setCompositeDisposableOnStop(@NonNull Disposable s) {
38 | if (compositeDisposableOnStop != null) {
39 | compositeDisposableOnStop.add(s);
40 | } else {
41 | compositeDisposableOnStop = new CompositeDisposable();
42 | compositeDisposableOnStop.add(s);
43 | }
44 | }
45 |
46 | public void setCompositeDisposableOnDestroy(Disposable s) {
47 | if (compositeDisposableOnDestroy != null) {
48 | compositeDisposableOnDestroy.add(s);
49 | } else {
50 | compositeDisposableOnDestroy = new CompositeDisposable();
51 | compositeDisposableOnDestroy.add(s);
52 | }
53 | }
54 |
55 | public void onStopDisposable() {
56 | if (compositeDisposableOnStop != null) {
57 | compositeDisposableOnStop.dispose();
58 | compositeDisposableOnStop.clear();
59 | compositeDisposableOnStop = null;
60 | }
61 | }
62 |
63 | public void onDestroy() {
64 | if (compositeDisposableOnDestroy != null) {
65 | compositeDisposableOnDestroy.dispose();
66 | compositeDisposableOnDestroy.clear();
67 | compositeDisposableOnDestroy = null;
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/ServerResultFunction.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | import com.seven.seven.common.utils.GsonTools;
4 | import com.seven.seven.common.utils.LogUtils;
5 |
6 | import java.util.function.Function;
7 |
8 | /**
9 | * Created by seven
10 | * on 2018/5/17
11 | * email:seven2016s@163.com
12 | */
13 |
14 | public class ServerResultFunction implements io.reactivex.functions.Function {
15 | @Override
16 | public Object apply(ResponseCustom responseCustom) {
17 | LogUtils.jsonE("服务器返回结果===>" + GsonTools.createGsonString(responseCustom));
18 |
19 | return responseCustom;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/ThreadSchedulersHelper.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network;
2 |
3 | import io.reactivex.Observable;
4 | import io.reactivex.ObservableSource;
5 | import io.reactivex.ObservableTransformer;
6 | import io.reactivex.android.schedulers.AndroidSchedulers;
7 | import io.reactivex.schedulers.Schedulers;
8 |
9 | /**
10 | * Created on 2018-03-20.
11 | * author:seven
12 | * email:seven2016s@163.com
13 | */
14 |
15 | public class ThreadSchedulersHelper {
16 | /* 上游处理网络请求用io线程(发布事件)
17 | * 线程上下游切换,上游执行完以后里面切换为主线程(接收事件)
18 | * */
19 | public static ObservableTransformer rxSchedulers() {
20 | return new ObservableTransformer() {
21 | @Override
22 | public ObservableSource apply(Observable upstream) {
23 | return upstream.subscribeOn(Schedulers.io())
24 | .observeOn(AndroidSchedulers.mainThread());
25 | }
26 | };
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/gank/GankHttpObserver.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network.gank;
2 |
3 | import android.util.Log;
4 |
5 | import com.seven.seven.common.network.ApiException;
6 | import com.seven.seven.common.network.RxLifeManager;
7 |
8 | import java.net.UnknownServiceException;
9 |
10 | import io.reactivex.Observer;
11 | import io.reactivex.disposables.Disposable;
12 |
13 | /**
14 | * Created on 2018-03-20.
15 | * author:seven
16 | * email:seven2016s@163.com
17 | */
18 |
19 | public abstract class GankHttpObserver implements Observer {
20 | private boolean flag = false;//是否切断上下游的事件传递
21 | public static final int UN_KNOWN_ERROR = 1000;//未知错误
22 |
23 | public GankHttpObserver() {
24 | }
25 |
26 | public GankHttpObserver(boolean isLink) {
27 | this.flag = isLink;
28 | }
29 |
30 | @Override
31 | public void onSubscribe(Disposable d) {
32 | this.onStart(d);
33 | if (flag) {
34 | RxLifeManager.getRxLifeManager().setCompositeDisposableOnStop(d);
35 | } else {
36 | RxLifeManager.getRxLifeManager().setCompositeDisposableOnDestroy(d);
37 | }
38 | }
39 |
40 | protected abstract void onStart(Disposable d);
41 |
42 | protected abstract void _onNext(T t);
43 |
44 | // protected abstract void _onError(ApiException e);
45 | protected abstract void _onError(ApiException e);
46 |
47 | /*
48 | * t==response
49 | * */
50 | @Override
51 | public void onNext(T t) {
52 | if (t != null) {
53 | this._onNext(t);
54 | }
55 |
56 | }
57 |
58 | @Override
59 | public void onError(Throwable e) {
60 | if (e instanceof ApiException || e instanceof UnknownServiceException) {
61 | _onError((ApiException) e);
62 | Log.e("onerror", "错误编码===" + ((ApiException) e).getCode() + "错误信息===" + ((ApiException) e).getMsg());
63 | } else {
64 | this._onError(new ApiException(e, UN_KNOWN_ERROR));
65 | }
66 | // this._onError(e);
67 | }
68 |
69 | @Override
70 | public void onComplete() {
71 |
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/gank/GankIoCustom.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network.gank;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created on 2018-03-20.
7 | * author:seven
8 | * email:seven2016s@163.com
9 | */
10 |
11 | public class GankIoCustom implements Serializable {
12 |
13 | public boolean isError() {
14 | return error;
15 | }
16 |
17 | public void setError(boolean error) {
18 | this.error = error;
19 | }
20 |
21 | public T getResults() {
22 | return results;
23 | }
24 |
25 | public void setResults(T results) {
26 | this.results = results;
27 | }
28 |
29 | private boolean error;
30 | private T results;
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/gank/GankIoObservable.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network.gank;
2 |
3 | import com.seven.seven.common.network.gank.GankIoCustom;
4 |
5 | import io.reactivex.Observable;
6 | import io.reactivex.android.schedulers.AndroidSchedulers;
7 | import io.reactivex.schedulers.Schedulers;
8 |
9 | /**
10 | * Created by seven
11 | * on 2018/5/17
12 | * email:seven2016s@163.com
13 | */
14 |
15 | public class GankIoObservable {
16 | public static Observable getObservable(Observable> customObservable) {
17 | Observable observable = customObservable
18 | // .map(new ServerResultFunction())
19 | // .onErrorResumeNext(new HttpResultFunction())
20 | .subscribeOn(Schedulers.io())
21 | .observeOn(AndroidSchedulers.mainThread());
22 | return observable;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/network/gank/GankResultObserver.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.network.gank;
2 |
3 | import com.seven.seven.common.network.ApiException;
4 | import com.seven.seven.common.network.HttpCommonObserver;
5 | import com.seven.seven.common.network.gank.GankIoCustom;
6 |
7 | import io.reactivex.disposables.Disposable;
8 |
9 | /**
10 | * Created on 2018-03-20.
11 | * author:seven
12 | * email:seven2016s@163.com
13 | */
14 |
15 | public abstract class GankResultObserver extends GankHttpObserver {
16 |
17 | protected abstract void onLoading(Disposable d);
18 |
19 | protected abstract void onSuccess(T o);
20 |
21 | protected abstract void onFail(ApiException e);
22 |
23 | @Override
24 | protected void onStart(Disposable d) {
25 | onLoading(d);
26 | }
27 |
28 | @Override
29 | protected void _onNext(T responseCustom) {
30 | onSuccess(responseCustom);
31 | }
32 |
33 | @Override
34 | protected void _onError(ApiException error) {
35 | onFail(error);
36 | // Log.e("网络处理异常", error.getMessage());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/utils/AppBarStateChangeListener.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.utils;
2 |
3 | import android.support.design.widget.AppBarLayout;
4 |
5 | public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {
6 |
7 | public enum State {
8 | EXPANDED,
9 | COLLAPSED,
10 | IDLE
11 | }
12 |
13 | private State mCurrentState = State.IDLE;
14 |
15 | @Override
16 | public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
17 | if (i == 0) {
18 | if (mCurrentState != State.EXPANDED) {
19 | onStateChanged(appBarLayout, State.EXPANDED);
20 | }
21 | mCurrentState = State.EXPANDED;
22 | } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
23 | if (mCurrentState != State.COLLAPSED) {
24 | onStateChanged(appBarLayout, State.COLLAPSED);
25 | }
26 | mCurrentState = State.COLLAPSED;
27 | } else {
28 | if (mCurrentState != State.IDLE) {
29 | onStateChanged(appBarLayout, State.IDLE);
30 | }
31 | mCurrentState = State.IDLE;
32 | }
33 | }
34 |
35 | public abstract void onStateChanged(AppBarLayout appBarLayout, State state);
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/utils/Constans.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.utils;
2 |
3 | /**
4 | * Created by seven
5 | * on 2018/5/17
6 | * email:seven2016s@163.com
7 | * eventbus的what记录以及一些常量的配置
8 | */
9 |
10 | public class Constans {
11 | /*
12 | * 网络监听
13 | * */
14 | public static final int NET_WORK_AVAILABLE = 0;//有网络
15 | public static final int NET_WORK_DISABLED = 1;//没网络
16 | /*
17 | * home模块 100~200
18 | * */
19 | public static final int HOMEDATA = 101;//获取首页数据成功
20 | public static final int HOMEBANNER = 102;//获取首页banner
21 | public static final int HOMEERROR = 100;//首页请求数据失败
22 | public static final int HOMEDASUCCESS = 103;//banner,homedata请求数据成功,取消loading
23 |
24 | public static final String COOKIE_PREF = "cookie_pref";//cookie保存
25 | /*
26 | * 登录注册用户相关10-20
27 | * */
28 | public static final int REGISTER = 10;//注册成功
29 | public static final int LOGIN = 11;//登录成功
30 | public static final int RELOGIN = 13;//重新登录
31 | public static final int USERERROR = 12;//用户相关错误
32 | public static final int USERERRORS = 14;//注册相关错误
33 | public static final String USERNAME = "user_name";//存储用户名
34 | public static final int COLLECTSIZE = 41;//获取收藏size
35 | public static final int COLLECTSIZEERROR = 42;//获取收藏size失败
36 | /*
37 | * webview模块 20-40
38 | * */
39 | public static final int COLLECT = 20;//收藏文章成功
40 | public static final int COLLECTERROR = 22;//收藏文章失败
41 |
42 | /*
43 | * 个人模块 40-60
44 | * */
45 | public static final int COLLECTLIST = 41;//获取收藏列表成功
46 | public static final int COLLECTLISTERROR = 42;//获取收藏列表失败
47 | public static final int DELETECOLLECT = 43;//获取收藏列表失败
48 | public static final int DELETECOLLECTERROR = 44;//获取收藏列表失败
49 |
50 | /*
51 | * 搜索模块 60~80
52 | * */
53 | public static final int HOTTAG = 60;//获取热门搜索词成功
54 | public static final int HOTTAGERROR = 61;//获取热门搜索词失败
55 | public static final int USINGURL = 62;//获取常用网址成功
56 | public static final int USINGURLERROR = 63;//获取常用网址失败
57 | public static final int SEARCHK = 64;//动态搜索成功
58 | public static final int SEARCHKERROR = 65;//动态搜索失败
59 |
60 | /*
61 | * 干货模块 80~99
62 | *
63 | * */
64 | public static final int GANKIO = 80;//获取干货福利成功
65 | public static final int GANKIOERROR = 81;//获取干货福利失败
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/utils/DensityUtil.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.utils;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by oi on 2017/12/6.
7 | * dp和px之间进行转换
8 | */
9 |
10 | public class DensityUtil {
11 | /**
12 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
13 | */
14 | public static int dip2px(Context context, float dpValue) {
15 | final float scale = context.getResources().getDisplayMetrics().density;
16 | return (int) (dpValue * scale + 0.5f);
17 | }
18 |
19 | /**
20 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
21 | */
22 | public static int px2dip(Context context, float pxValue) {
23 | final float scale = context.getResources().getDisplayMetrics().density;
24 | return (int) (pxValue / scale + 0.5f);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/utils/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.utils;
2 |
3 | import android.content.Context;
4 |
5 | import java.io.File;
6 | import java.util.Arrays;
7 |
8 | /**
9 | * Created by Liuc on 2017-12-19.
10 | * 辅助创建文件夹和文件
11 | */
12 |
13 | public class FileUtils {
14 |
15 |
16 | /**
17 | * 创建一个新的文件用来存储图片
18 | *
19 | * @param outputfile 输出路径
20 | * @return 是否创建成功
21 | */
22 | public static boolean creatFile(File outputfile) {
23 | boolean flag = true;
24 | try {
25 | outputfile.deleteOnExit();
26 | outputfile.createNewFile();
27 | } catch (Exception e) {
28 | e.printStackTrace();
29 | }
30 | return flag;
31 | }
32 |
33 |
34 | /**
35 | * 创建一个新的文件用来存储图片
36 | *
37 | * @param outputfile 输出路径
38 | * @return 是否创建成功
39 | */
40 | public static boolean creatDirs(File outputfile) {
41 | boolean flag = true;
42 | try {
43 | outputfile.deleteOnExit();
44 | flag = outputfile.mkdirs();
45 | } catch (Exception e) {
46 | e.printStackTrace();
47 | }
48 | return flag;
49 | }
50 |
51 | /**
52 | * 判断assets文件夹下的文件是否存在
53 | *
54 | * @return false 不存在 true 存在
55 | */
56 | public static boolean isFileExists(Context context, String filename) {
57 | String[] names = new File(context.getCacheDir().getAbsolutePath() + File.separator + "error_1").list();
58 | LogUtils.e(Arrays.toString(names));
59 | if (names != null) {
60 | for (String name : names) {
61 | if (name.contains(filename.trim())) {
62 | return true;
63 | }
64 | }
65 | }
66 | return false;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/utils/GlideUtils.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.utils;
2 |
3 | import android.graphics.Bitmap;
4 | import android.widget.ImageView;
5 |
6 | import com.bumptech.glide.Glide;
7 | import com.bumptech.glide.request.RequestOptions;
8 | import com.seven.seven.ui.MyApplication;
9 |
10 | /**
11 | * Created on 2018-05-28.
12 | * author:seven
13 | * email:seven2016s@163.com
14 | */
15 |
16 | public class GlideUtils {
17 | /*
18 | * 正常加载
19 | * */
20 | public static void loadImageview(ImageView imageview, String path) {
21 | Glide.with(MyApplication.getContext()).load(path).into(imageview);
22 | }
23 |
24 | /*
25 | *
26 | * 加载带有占位图的view
27 | * */
28 | public static void loadImageViewLoading(ImageView imageView, Object path, int errorPath, int loadingPath) {
29 | RequestOptions requestOptions = new RequestOptions();
30 | Glide.with(MyApplication.getContext()).load(path)
31 | .apply(requestOptions.placeholder(loadingPath).error(errorPath))
32 | .into(imageView);
33 | }
34 |
35 | /*
36 | * 加载指定大小的image
37 | * */
38 | public static void loadImageViewSize(ImageView imageView, String path, int loadingPath, int errorPath, int width, int height) {
39 | RequestOptions requestOptions = new RequestOptions();
40 | Glide.with(MyApplication.getContext()).load(path).apply(requestOptions.override(width, height)
41 | .placeholder(loadingPath).error(errorPath))
42 | .into(imageView);
43 | }
44 |
45 | /*
46 | * 裁剪大小,设置缓存模式,防止oom(不缓存)
47 | *
48 | * */
49 | public static void loadImageViewOOM(ImageView imageView, int loadingPath, int errorPath, String path, int height, int width) {
50 | RequestOptions requestOptions = new RequestOptions();
51 | Glide.with(MyApplication.getContext()).load(path)
52 | .apply(requestOptions.override(width, height).skipMemoryCache(true)
53 | .placeholder(loadingPath).error(errorPath))
54 | .into(imageView);
55 | }
56 |
57 | /*
58 | * 加载圆形图片
59 | * */
60 | public static void loadImageViewCircle(ImageView imageView, String path, int loadingPath, int errorPath) {
61 | RequestOptions requestOptions = new RequestOptions();
62 | Glide.with(MyApplication.getContext()).asBitmap().load(path)
63 | .apply(requestOptions.skipMemoryCache(true).optionalCircleCrop()
64 | .placeholder(loadingPath).error(errorPath))
65 | .into(imageView);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/seven/seven/common/utils/GsonTools.java:
--------------------------------------------------------------------------------
1 | package com.seven.seven.common.utils;
2 |
3 |
4 | import com.google.gson.Gson;
5 | import com.google.gson.reflect.TypeToken;
6 |
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | public class GsonTools {
11 |
12 | public GsonTools() {
13 | // TODO Auto-generated constructor stub
14 | }
15 |
16 | public static String createGsonString(Object object) {
17 | Gson gson = new Gson();
18 | String gsonString = gson.toJson(object);
19 | return gsonString;
20 | }
21 |
22 | public static T changeGsonToBean(String gsonString, Class cls) {
23 | Gson gson = new Gson();
24 | T t = gson.fromJson(gsonString, cls);
25 | return t;
26 | }
27 |
28 | public static List changeGsonToList(String gsonString, Class cls) {
29 | Gson gson = new Gson();
30 | List list = gson.fromJson(gsonString, new TypeToken>() {
31 | }.getType());
32 | return list;
33 | }
34 |
35 |
36 | public static List