├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── movie.png
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── img1.jpg
│ │ │ │ ├── img2.jpg
│ │ │ │ ├── img3.jpg
│ │ │ │ ├── img4.jpg
│ │ │ │ ├── img5.jpg
│ │ │ │ ├── point_focus.png
│ │ │ │ ├── point_normal.png
│ │ │ │ └── side_nav_bar.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── attrs.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── arrays.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── drawables.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── dimens.xml
│ │ │ ├── anim
│ │ │ │ ├── left_out.xml
│ │ │ │ └── right_in.xml
│ │ │ ├── drawable-v21
│ │ │ │ ├── ic_menu_send.xml
│ │ │ │ ├── ic_menu_slideshow.xml
│ │ │ │ ├── ic_menu_gallery.xml
│ │ │ │ ├── ic_menu_manage.xml
│ │ │ │ ├── ic_menu_camera.xml
│ │ │ │ └── ic_menu_share.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── menu
│ │ │ │ ├── main.xml
│ │ │ │ └── activity_main_drawer.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_gridmovie.xml
│ │ │ │ ├── content_main.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── fragment_hotmovie.xml
│ │ │ │ ├── custom_viewpager.xml
│ │ │ │ ├── item_movie.xml
│ │ │ │ ├── nav_header_main.xml
│ │ │ │ ├── single_ball_loading.xml
│ │ │ │ ├── activity_movieinfo.xml
│ │ │ │ ├── app_bar_main.xml
│ │ │ │ └── menu_movie.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── toryang
│ │ │ │ └── sampledemo
│ │ │ │ ├── ui
│ │ │ │ ├── view
│ │ │ │ │ ├── TopDataView.java
│ │ │ │ │ ├── MvpView.java
│ │ │ │ │ └── DataView.java
│ │ │ │ ├── BaseActivity.java
│ │ │ │ ├── BaseFragment.java
│ │ │ │ ├── adapter
│ │ │ │ │ ├── ViewpagerAdapter.java
│ │ │ │ │ ├── GridSpacingItemDecoration.java
│ │ │ │ │ ├── GridItemClick.java
│ │ │ │ │ ├── LoopAdapter.java
│ │ │ │ │ ├── GridAdapter.java
│ │ │ │ │ └── OutRecyclerAdapter.java
│ │ │ │ ├── fragment
│ │ │ │ │ ├── TopMovFragment.java
│ │ │ │ │ └── HotMovieFragment.java
│ │ │ │ └── activity
│ │ │ │ │ ├── MovieInfoActivity.java
│ │ │ │ │ ├── GridMovieActivity.java
│ │ │ │ │ └── MainActivity.java
│ │ │ │ ├── config
│ │ │ │ └── IPAddress.java
│ │ │ │ ├── presenter
│ │ │ │ ├── Presenter.java
│ │ │ │ ├── BasePresenter.java
│ │ │ │ ├── Top250PresenterImpl.java
│ │ │ │ └── HotMoviePresenterImpl.java
│ │ │ │ ├── utils
│ │ │ │ ├── Util.java
│ │ │ │ ├── NetworkUtils.java
│ │ │ │ └── Log.java
│ │ │ │ ├── api
│ │ │ │ ├── NetService.java
│ │ │ │ └── InitRetrofit.java
│ │ │ │ ├── App.java
│ │ │ │ ├── entities
│ │ │ │ ├── usbox
│ │ │ │ │ ├── Images.java
│ │ │ │ │ ├── Avatars.java
│ │ │ │ │ ├── Avatars_.java
│ │ │ │ │ ├── UsBoxEntity.java
│ │ │ │ │ ├── Cast.java
│ │ │ │ │ ├── Director.java
│ │ │ │ │ ├── Rating.java
│ │ │ │ │ ├── Subject.java
│ │ │ │ │ └── Subject_.java
│ │ │ │ └── movieEntitiy
│ │ │ │ │ ├── Images.java
│ │ │ │ │ ├── Avatars.java
│ │ │ │ │ ├── Avatars_.java
│ │ │ │ │ ├── Cast.java
│ │ │ │ │ ├── Director.java
│ │ │ │ │ ├── Rating.java
│ │ │ │ │ ├── movieinfo.java
│ │ │ │ │ └── Subject.java
│ │ │ │ ├── loading
│ │ │ │ ├── SingleBall.java
│ │ │ │ └── MyLoading.java
│ │ │ │ └── common
│ │ │ │ ├── OkhttpUtil.java
│ │ │ │ └── OkHttp3Downloader.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── toryang
│ │ │ └── sampledemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── toryang
│ │ └── sampledemo
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | SampleDemo
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/movie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/mipmap-xhdpi/movie.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/img1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/drawable-xxhdpi/img1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/img2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/drawable-xxhdpi/img2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/img3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/drawable-xxhdpi/img3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/img4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/drawable-xxhdpi/img4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/img5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/drawable-xxhdpi/img5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/point_focus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/drawable-xxhdpi/point_focus.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/point_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/toryangchen/SampleDemo/HEAD/app/src/main/res/drawable-xxhdpi/point_normal.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/left_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/right_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/view/TopDataView.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.view;
2 |
3 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
4 |
5 | /**
6 | * Created by toryang on 5/24/16.
7 | */
8 | public interface TopDataView extends MvpView {
9 |
10 | void dataBack(Movieinfo top250Entity);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/view/MvpView.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.view;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by toryang on 16/4/27.
7 | */
8 | public interface MvpView {
9 |
10 | void startLoading();
11 |
12 | void hideLoading();
13 |
14 | void showError(String msg);
15 |
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/side_nav_bar.xml:
--------------------------------------------------------------------------------
1 |
3 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/config/IPAddress.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.config;
2 |
3 | /**
4 | * Created by toryang on 16/4/26.
5 | */
6 | public class IPAddress {
7 |
8 | public static final String url = "https://api.douban.com";
9 | public static final String totalUrl = "https://api.douban.com/v2/movie/us_box";
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/presenter/Presenter.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.presenter;
2 |
3 | import com.toryang.sampledemo.ui.view.MvpView;
4 |
5 | /**
6 | * Created by toryang on 16/4/27.
7 | */
8 | public interface Presenter {
9 |
10 | void attachView(V mvpView);
11 |
12 | void detachView();
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_send.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - 首页
5 | - top250
6 |
7 |
8 |
9 |
10 | - 热门电影
11 | - 近期上映
12 | - 北美票房榜
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/toryang/sampledemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/view/DataView.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.view;
2 |
3 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
4 | import com.toryang.sampledemo.entities.usbox.UsBoxEntity;
5 |
6 | /**
7 | * Created by toryang on 16/4/27.
8 | */
9 | public interface DataView extends MvpView {
10 |
11 | void loadData(UsBoxEntity usBoxEntity, Movieinfo comingSoon, Movieinfo inThreatEntity);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/toryang/sampledemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo;
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/main/res/drawable-v21/ic_menu_slideshow.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_gallery.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_manage.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 豆瓣电影Api
3 |
4 | Open navigation drawer
5 | Close navigation drawer
6 |
7 | Settings
8 |
9 |
10 | 热门电影
11 | 近期上映
12 | 北美票房榜
13 |
14 | 更多 >
15 |
16 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 | - @android:drawable/ic_menu_camera
3 | - @android:drawable/ic_menu_gallery
4 | - @android:drawable/ic_menu_slideshow
5 | - @android:drawable/ic_menu_manage
6 | - @android:drawable/ic_menu_share
7 | - @android:drawable/ic_menu_send
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_camera.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_gridmovie.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import butterknife.ButterKnife;
8 |
9 | /**
10 | * Created by toryang on 16/4/25.
11 | */
12 | public abstract class BaseActivity extends AppCompatActivity {
13 |
14 | @Override
15 | protected void onCreate(@Nullable Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | }
18 |
19 | @Override
20 | protected void onResume() {
21 | super.onResume();
22 | }
23 |
24 | public abstract void operateView();
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/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/toryang/Library/Android/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/main/java/com/toryang/sampledemo/utils/Util.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.utils;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by toryang on 16/4/26.
7 | */
8 | public class Util {
9 | /**
10 | * dpתpx
11 | *
12 | */
13 | public static int dip2px(Context ctx, float dpValue) {
14 | final float scale = ctx.getResources().getDisplayMetrics().density;
15 | return (int) (dpValue * scale + 0.5f);
16 | }
17 |
18 |
19 | /**
20 | * pxתdp
21 | */
22 | public static int px2dip(Context ctx,float pxValue) {
23 | final float scale = ctx.getResources().getDisplayMetrics().density;
24 | return (int) (pxValue / scale + 0.5f);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/api/NetService.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.api;
2 |
3 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
4 | import com.toryang.sampledemo.entities.usbox.UsBoxEntity;
5 |
6 | import retrofit2.http.GET;
7 | import rx.Observable;
8 |
9 | /**
10 | * Created by toryang on 16/4/26.
11 | */
12 | public interface NetService {
13 |
14 | @GET("/v2/movie/us_box")
15 | Observable getHotMovie();
16 |
17 | @GET("/v2/movie/in_theaters")
18 | Observable getInTheaters ();
19 |
20 | @GET("/v2/movie/coming_soon")
21 | Observable getComingSoon();
22 |
23 | @GET("/v2/movie/top250")
24 | Observable getTop250();
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_share.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.view.View;
5 |
6 | import com.toryang.sampledemo.loading.MyLoading;
7 | import com.toryang.sampledemo.ui.view.MvpView;
8 |
9 | /**
10 | * Created by toryang on 16/4/26.
11 | */
12 | public class BaseFragment extends Fragment implements MvpView {
13 |
14 | MyLoading myLoading;
15 |
16 | public void setMyLoading(MyLoading myLoading) {
17 | this.myLoading = myLoading;
18 | }
19 | @Override
20 | public void startLoading() {
21 | myLoading.start();
22 | }
23 |
24 | @Override
25 | public void hideLoading() {
26 | myLoading.stop();
27 | myLoading.setVisibility(View.GONE);
28 | }
29 |
30 | @Override
31 | public void showError(String msg) {
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/.idea/gradle.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 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 160dp
5 |
6 | 16dp
7 | 16dp
8 | 16dp
9 |
10 | 18sp
11 | 14sp
12 | 14sp
13 |
14 | 280dp
15 |
16 | 20dp
17 |
18 | 10dp
19 |
20 | 140dp
21 | 100dp
22 |
23 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/presenter/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.presenter;
2 |
3 | import com.toryang.sampledemo.ui.view.MvpView;
4 |
5 | /**
6 | * Created by toryang on 16/4/27.
7 | */
8 | public class BasePresenter implements Presenter {
9 |
10 | private T mMvpView;
11 |
12 | @Override
13 | public void attachView(T mvpView) {
14 | mMvpView = mvpView;
15 | }
16 |
17 | @Override
18 | public void detachView() {
19 | mMvpView = null;
20 | }
21 |
22 | public boolean isViewAttached() {
23 | return mMvpView != null;
24 | }
25 |
26 | public T getMvpView() {
27 | return mMvpView;
28 | }
29 |
30 | public void checkViewAttached() {
31 | if (!isViewAttached()) throw new MvpViewNotAttachedException();
32 | }
33 |
34 |
35 | public static class MvpViewNotAttachedException extends RuntimeException{
36 | public MvpViewNotAttachedException(){
37 | super("Please call Presenter.attachView(MvpView) before" +
38 | " requesting data to the Presenter");
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_hotmovie.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
22 |
23 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/App.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo;
2 |
3 | import android.app.Application;
4 |
5 | import com.facebook.drawee.backends.pipeline.Fresco;
6 | import com.squareup.picasso.Picasso;
7 | import com.toryang.sampledemo.common.OkHttp3Downloader;
8 |
9 | import okhttp3.OkHttpClient;
10 |
11 | /**
12 | * Created by toryang on 16/4/28.
13 | */
14 | public class App extends Application {
15 |
16 | private static App instace;
17 |
18 | public static App getInstace(){
19 | return instace;
20 | }
21 |
22 | public static Picasso mPicasso;
23 | @Override
24 | public void onCreate() {
25 | super.onCreate();
26 | instace = this;
27 | setUpPicasso();
28 | Fresco.initialize(this);
29 | }
30 |
31 | public void setUpPicasso(){
32 |
33 | Picasso picasso = new Picasso.Builder(this)
34 | .downloader(new OkHttp3Downloader(new OkHttpClient()))
35 | .build();
36 | Picasso.setSingletonInstance(picasso);
37 | mPicasso = picasso;
38 | }
39 |
40 | public static Picasso getPicasso(){
41 | return mPicasso;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/adapter/ViewpagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * Created by toryang on 16/4/26.
12 | */
13 | public class ViewpagerAdapter extends FragmentPagerAdapter {
14 | private List mFragments = new ArrayList();
15 | private List mFragmentTitles = new ArrayList();
16 |
17 | public ViewpagerAdapter(FragmentManager fm) {
18 | super(fm);
19 | }
20 |
21 | public void addFragments(Fragment fragment,String titles){
22 | mFragments.add(fragment);
23 | mFragmentTitles.add(titles);
24 | }
25 |
26 | @Override
27 | public Fragment getItem(int position) {
28 | return mFragments.get(position);
29 | }
30 |
31 | @Override
32 | public int getCount() {
33 | return mFragments.size();
34 | }
35 |
36 | @Override
37 | public CharSequence getPageTitle(int position) {
38 | return mFragmentTitles.get(position);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_main_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
37 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/custom_viewpager.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
19 |
20 |
24 |
25 |
30 |
31 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_movie.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
20 |
21 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_header_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
27 |
28 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Images.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Images {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Avatars.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Avatars {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Avatars_.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Avatars_ {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/adapter/GridSpacingItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.adapter;
2 |
3 | import android.graphics.Rect;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by toryang on 5/25/16.
9 | */
10 | public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
11 | private int spanCount;
12 | private int spacing;
13 | private boolean includeEdge;
14 |
15 | public GridSpacingItemDecoration(int spanCount,int spacing,boolean includeEdge){
16 | this.spacing = spacing;
17 | this.spanCount = spanCount;
18 | this.includeEdge = includeEdge;
19 | }
20 |
21 | @Override
22 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
23 | int position = parent.getChildAdapterPosition(view);
24 | int column = position % spanCount;
25 | if (includeEdge){
26 | outRect.left = spacing-column*spacing / spanCount;
27 | outRect.right = (column + 1)*spacing / spanCount;
28 |
29 | if (position < spanCount){
30 | outRect.top = spacing;
31 | }
32 | outRect.bottom = spacing;
33 | }else {
34 | outRect.left = column*spacing/spanCount;
35 | outRect.right = spacing - (column + 1)*spacing/spanCount;
36 | if (position >= spanCount){
37 | outRect.top = spacing;
38 | }
39 | }
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Images.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Images {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Avatars.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Avatars {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Avatars_.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Avatars_ {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/utils/NetworkUtils.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.utils;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.NetworkInfo;
6 |
7 | import com.toryang.sampledemo.App;
8 |
9 | /**
10 | * Created by toryang on 16/4/28.
11 | */
12 | public class NetworkUtils {
13 |
14 | /**
15 | * 判断是否有网络连接
16 | * @return
17 | */
18 |
19 | public static boolean isNetworkConnected(){
20 |
21 | ConnectivityManager mConnectivityManager = (ConnectivityManager) App.getInstace()
22 | .getSystemService(Context.CONNECTIVITY_SERVICE);
23 |
24 | NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
25 |
26 | if (mNetworkInfo != null){
27 | return mNetworkInfo.isAvailable();
28 | }
29 |
30 |
31 | return false;
32 | }
33 |
34 | /**
35 | * 判断Wi-Fi网络是否有用
36 | * @param context
37 | * @return
38 | */
39 | public boolean isWifiConnected(Context context){
40 | if(context != null){
41 | ConnectivityManager mConnectivityManager = (ConnectivityManager)context
42 | .getSystemService(Context.CONNECTIVITY_SERVICE);
43 |
44 | NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
45 |
46 | if (mWiFiNetworkInfo != null){
47 | return mWiFiNetworkInfo.isAvailable();
48 | }
49 | }
50 | return false;
51 | }
52 |
53 |
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/single_ball_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
27 |
28 |
33 |
34 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/UsBoxEntity.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class UsBoxEntity {
11 |
12 | @SerializedName("date")
13 | @Expose
14 | private String date;
15 | @SerializedName("subjects")
16 | @Expose
17 | private List subjects = new ArrayList();
18 | @SerializedName("title")
19 | @Expose
20 | private String title;
21 |
22 | /**
23 | *
24 | * @return
25 | * The date
26 | */
27 | public String getDate() {
28 | return date;
29 | }
30 |
31 | /**
32 | *
33 | * @param date
34 | * The date
35 | */
36 | public void setDate(String date) {
37 | this.date = date;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The subjects
44 | */
45 | public List getSubjects() {
46 | return subjects;
47 | }
48 |
49 | /**
50 | *
51 | * @param subjects
52 | * The subjects
53 | */
54 | public void setSubjects(List subjects) {
55 | this.subjects = subjects;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The title
62 | */
63 | public String getTitle() {
64 | return title;
65 | }
66 |
67 | /**
68 | *
69 | * @param title
70 | * The title
71 | */
72 | public void setTitle(String title) {
73 | this.title = title;
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/adapter/GridItemClick.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.GestureDetector;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 |
9 | /**
10 | * Created by toryang on 5/25/16.
11 | */
12 | public class GridItemClick implements RecyclerView.OnItemTouchListener {
13 |
14 | private OnItemClickListener mListener;
15 | public interface OnItemClickListener{
16 | public void onItemClick(View view,int position);
17 | }
18 |
19 | GestureDetector mGestureDetector;
20 |
21 | public GridItemClick(Context context, OnItemClickListener listener){
22 | mListener = listener;
23 | mGestureDetector = new GestureDetector(context,new GestureDetector.SimpleOnGestureListener(){
24 | @Override
25 | public boolean onSingleTapUp(MotionEvent e) {
26 | return true;
27 | }
28 | });
29 | }
30 |
31 | @Override
32 | public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
33 | View childView = rv.findChildViewUnder(e.getX(),e.getY());
34 | if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)){
35 | mListener.onItemClick(childView,rv.getChildAdapterPosition(childView));
36 | }
37 | return false;
38 | }
39 |
40 | @Override
41 | public void onTouchEvent(RecyclerView rv, MotionEvent e) {
42 |
43 | }
44 |
45 | @Override
46 | public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
47 |
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Cast.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 |
8 | public class Cast {
9 |
10 | @SerializedName("alt")
11 | @Expose
12 | private String alt;
13 | @SerializedName("avatars")
14 | @Expose
15 | private Avatars avatars;
16 | @SerializedName("name")
17 | @Expose
18 | private String name;
19 | @SerializedName("id")
20 | @Expose
21 | private String id;
22 |
23 | /**
24 | *
25 | * @return
26 | * The alt
27 | */
28 | public String getAlt() {
29 | return alt;
30 | }
31 |
32 | /**
33 | *
34 | * @param alt
35 | * The alt
36 | */
37 | public void setAlt(String alt) {
38 | this.alt = alt;
39 | }
40 |
41 | /**
42 | *
43 | * @return
44 | * The avatars
45 | */
46 | public Avatars getAvatars() {
47 | return avatars;
48 | }
49 |
50 | /**
51 | *
52 | * @param avatars
53 | * The avatars
54 | */
55 | public void setAvatars(Avatars avatars) {
56 | this.avatars = avatars;
57 | }
58 |
59 | /**
60 | *
61 | * @return
62 | * The name
63 | */
64 | public String getName() {
65 | return name;
66 | }
67 |
68 | /**
69 | *
70 | * @param name
71 | * The name
72 | */
73 | public void setName(String name) {
74 | this.name = name;
75 | }
76 |
77 | /**
78 | *
79 | * @return
80 | * The id
81 | */
82 | public String getId() {
83 | return id;
84 | }
85 |
86 | /**
87 | *
88 | * @param id
89 | * The id
90 | */
91 | public void setId(String id) {
92 | this.id = id;
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Cast.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Cast {
8 |
9 | @SerializedName("alt")
10 | @Expose
11 | private String alt;
12 | @SerializedName("avatars")
13 | @Expose
14 | private Avatars avatars;
15 | @SerializedName("name")
16 | @Expose
17 | private String name;
18 | @SerializedName("id")
19 | @Expose
20 | private String id;
21 |
22 | /**
23 | *
24 | * @return
25 | * The alt
26 | */
27 | public String getAlt() {
28 | return alt;
29 | }
30 |
31 | /**
32 | *
33 | * @param alt
34 | * The alt
35 | */
36 | public void setAlt(String alt) {
37 | this.alt = alt;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The avatars
44 | */
45 | public Avatars getAvatars() {
46 | return avatars;
47 | }
48 |
49 | /**
50 | *
51 | * @param avatars
52 | * The avatars
53 | */
54 | public void setAvatars(Avatars avatars) {
55 | this.avatars = avatars;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The name
62 | */
63 | public String getName() {
64 | return name;
65 | }
66 |
67 | /**
68 | *
69 | * @param name
70 | * The name
71 | */
72 | public void setName(String name) {
73 | this.name = name;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The id
80 | */
81 | public String getId() {
82 | return id;
83 | }
84 |
85 | /**
86 | *
87 | * @param id
88 | * The id
89 | */
90 | public void setId(String id) {
91 | this.id = id;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Director.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Director {
8 |
9 | @SerializedName("alt")
10 | @Expose
11 | private String alt;
12 | @SerializedName("avatars")
13 | @Expose
14 | private Avatars_ avatars;
15 | @SerializedName("name")
16 | @Expose
17 | private String name;
18 | @SerializedName("id")
19 | @Expose
20 | private String id;
21 |
22 | /**
23 | *
24 | * @return
25 | * The alt
26 | */
27 | public String getAlt() {
28 | return alt;
29 | }
30 |
31 | /**
32 | *
33 | * @param alt
34 | * The alt
35 | */
36 | public void setAlt(String alt) {
37 | this.alt = alt;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The avatars
44 | */
45 | public Avatars_ getAvatars() {
46 | return avatars;
47 | }
48 |
49 | /**
50 | *
51 | * @param avatars
52 | * The avatars
53 | */
54 | public void setAvatars(Avatars_ avatars) {
55 | this.avatars = avatars;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The name
62 | */
63 | public String getName() {
64 | return name;
65 | }
66 |
67 | /**
68 | *
69 | * @param name
70 | * The name
71 | */
72 | public void setName(String name) {
73 | this.name = name;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The id
80 | */
81 | public String getId() {
82 | return id;
83 | }
84 |
85 | /**
86 | *
87 | * @param id
88 | * The id
89 | */
90 | public void setId(String id) {
91 | this.id = id;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Director.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Director {
8 |
9 | @SerializedName("alt")
10 | @Expose
11 | private String alt;
12 | @SerializedName("avatars")
13 | @Expose
14 | private Avatars_ avatars;
15 | @SerializedName("name")
16 | @Expose
17 | private String name;
18 | @SerializedName("id")
19 | @Expose
20 | private String id;
21 |
22 | /**
23 | *
24 | * @return
25 | * The alt
26 | */
27 | public String getAlt() {
28 | return alt;
29 | }
30 |
31 | /**
32 | *
33 | * @param alt
34 | * The alt
35 | */
36 | public void setAlt(String alt) {
37 | this.alt = alt;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The avatars
44 | */
45 | public Avatars_ getAvatars() {
46 | return avatars;
47 | }
48 |
49 | /**
50 | *
51 | * @param avatars
52 | * The avatars
53 | */
54 | public void setAvatars(Avatars_ avatars) {
55 | this.avatars = avatars;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The name
62 | */
63 | public String getName() {
64 | return name;
65 | }
66 |
67 | /**
68 | *
69 | * @param name
70 | * The name
71 | */
72 | public void setName(String name) {
73 | this.name = name;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The id
80 | */
81 | public String getId() {
82 | return id;
83 | }
84 |
85 | /**
86 | *
87 | * @param id
88 | * The id
89 | */
90 | public void setId(String id) {
91 | this.id = id;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Rating.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Rating {
8 |
9 | @SerializedName("max")
10 | @Expose
11 | private Integer max;
12 | @SerializedName("average")
13 | @Expose
14 | private Double average;
15 | @SerializedName("stars")
16 | @Expose
17 | private String stars;
18 | @SerializedName("min")
19 | @Expose
20 | private Integer min;
21 |
22 | /**
23 | *
24 | * @return
25 | * The max
26 | */
27 | public Integer getMax() {
28 | return max;
29 | }
30 |
31 | /**
32 | *
33 | * @param max
34 | * The max
35 | */
36 | public void setMax(Integer max) {
37 | this.max = max;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The average
44 | */
45 | public Double getAverage() {
46 | return average;
47 | }
48 |
49 | /**
50 | *
51 | * @param average
52 | * The average
53 | */
54 | public void setAverage(Double average) {
55 | this.average = average;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The stars
62 | */
63 | public String getStars() {
64 | return stars;
65 | }
66 |
67 | /**
68 | *
69 | * @param stars
70 | * The stars
71 | */
72 | public void setStars(String stars) {
73 | this.stars = stars;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The min
80 | */
81 | public Integer getMin() {
82 | return min;
83 | }
84 |
85 | /**
86 | *
87 | * @param min
88 | * The min
89 | */
90 | public void setMin(Integer min) {
91 | this.min = min;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Subject.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Subject {
8 |
9 | @SerializedName("box")
10 | @Expose
11 | private Integer box;
12 | @SerializedName("new")
13 | @Expose
14 | private Boolean _new;
15 | @SerializedName("rank")
16 | @Expose
17 | private Integer rank;
18 | @SerializedName("subject")
19 | @Expose
20 | private Subject_ subject;
21 |
22 | /**
23 | *
24 | * @return
25 | * The box
26 | */
27 | public Integer getBox() {
28 | return box;
29 | }
30 |
31 | /**
32 | *
33 | * @param box
34 | * The box
35 | */
36 | public void setBox(Integer box) {
37 | this.box = box;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The _new
44 | */
45 | public Boolean getNew() {
46 | return _new;
47 | }
48 |
49 | /**
50 | *
51 | * @param _new
52 | * The new
53 | */
54 | public void setNew(Boolean _new) {
55 | this._new = _new;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The rank
62 | */
63 | public Integer getRank() {
64 | return rank;
65 | }
66 |
67 | /**
68 | *
69 | * @param rank
70 | * The rank
71 | */
72 | public void setRank(Integer rank) {
73 | this.rank = rank;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The subject
80 | */
81 | public Subject_ getSubject() {
82 | return subject;
83 | }
84 |
85 | /**
86 | *
87 | * @param subject
88 | * The subject
89 | */
90 | public void setSubject(Subject_ subject) {
91 | this.subject = subject;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Rating.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Rating {
8 |
9 | @SerializedName("max")
10 | @Expose
11 | private Integer max;
12 | @SerializedName("average")
13 | @Expose
14 | private Double average;
15 | @SerializedName("stars")
16 | @Expose
17 | private String stars;
18 | @SerializedName("min")
19 | @Expose
20 | private Integer min;
21 |
22 | /**
23 | *
24 | * @return
25 | * The max
26 | */
27 | public Integer getMax() {
28 | return max;
29 | }
30 |
31 | /**
32 | *
33 | * @param max
34 | * The max
35 | */
36 | public void setMax(Integer max) {
37 | this.max = max;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The average
44 | */
45 | public Double getAverage() {
46 | return average;
47 | }
48 |
49 | /**
50 | *
51 | * @param average
52 | * The average
53 | */
54 | public void setAverage(Double average) {
55 | this.average = average;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The stars
62 | */
63 | public String getStars() {
64 | return stars;
65 | }
66 |
67 | /**
68 | *
69 | * @param stars
70 | * The stars
71 | */
72 | public void setStars(String stars) {
73 | this.stars = stars;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The min
80 | */
81 | public Integer getMin() {
82 | return min;
83 | }
84 |
85 | /**
86 | *
87 | * @param min
88 | * The min
89 | */
90 | public void setMin(Integer min) {
91 | this.min = min;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 从零开始开发一款Android App
2 |
3 | MVP project Demo with some open Source Tools
4 |
5 |
6 | [原文链接](http://www.jianshu.com/p/a58d15ef5c8b)
7 |
8 | >最近准备开始写一个系列的Android开发blogs,算是对之前开发做一些总结,预计会写十一篇,以下为文章目录:(持续更新中!)
9 |
10 | **入门篇:**
11 | [第一篇:开发环境篇](http://www.jianshu.com/p/b20c9c6993f5)
12 | [第二篇:材料设计篇](http://www.jianshu.com/p/47b81f3a0b31)
13 | [第三篇:规范开发篇](http://www.jianshu.com/p/be0d9c0908f2)
14 | [第四篇:从项目开发到上架篇](http://www.jianshu.com/p/8b0483510bf9)(篇章调整,最后更新)
15 |
16 | **进阶篇:**
17 | [第五篇:设计模式篇](http://www.jianshu.com/p/fa92ca51bdb0)
18 | [第六篇:网络请求篇(上)](http://www.jianshu.com/p/b084b6d91260)
19 | [网络请求篇(下)](http://www.jianshu.com/p/4c0b9793d0b7)
20 | [第七篇:图片处理篇](http://www.jianshu.com/p/9b93737bfa88)
21 | [第八篇:数据库篇](http://www.jianshu.com/p/260dda970e19)
22 | [第九篇:开源资源篇](http://www.jianshu.com/p/bf78e484fc4e)
23 |
24 | **高阶篇:**
25 | [第十篇:自定义控件篇](http://www.jianshu.com/p/2266c6b82cb3)
26 | [第十一篇:跨进程篇](http://www.jianshu.com/p/a4a5ca43ce97)
27 |
28 | ##关于Demo
29 | * 写这个系列的文章的同时,也在做一个小Demo。功能很简单,利用豆瓣电影Api实现一款基于Android的电影集合的App。[star me on GitHub!](https://github.com/ToryangChen/SampleDemo)
30 |
31 | * 该项目的数据源来自于[豆瓣](https://developers.douban.com/wiki/?title=guide);
32 |
33 | * 项目用到的第三方类库(博客中写到的类库):[ButterKnife](http://jakewharton.github.io/butterknife/), [RxJava](https://github.com/ReactiveX/RxJava/wiki), [Volley](https://github.com/mcxiaoke/android-volley), [Retrofit2.0](http://square.github.io/retrofit/), [OkHttp](http://square.github.io/okhttp/), [Picasso](http://square.github.io/picasso/), [Fresco](https://github.com/facebook/fresco)等
34 |
35 | 看看目前的效果:
36 |
37 | 
38 |
39 | ##最后的话
40 |
41 | 该系列的文章对Android开发的内容涉及较广,从最基础的开发工具的使用到项目的打包发布,从Android材料设计到网络开发,从数据库的应用到自定义控件。本文也许不能面面俱到地将Android开发的内容全部罗列,但是这一定是对初学者的一份学习大纲。如果读者对其他方面的开发内容有需求,可以在评论留言,我将整理出来分享给大家。感谢大家的支持!
42 |
43 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.neenbedankt.android-apt'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.3"
7 |
8 | signingConfigs {
9 | release {
10 | storeFile file("SampleDemo.jks")
11 | storePassword "123456"
12 | keyAlias "Demo"
13 | keyPassword "123456"
14 | }
15 | }
16 | defaultConfig {
17 | applicationId "com.toryang.sampledemo"
18 | minSdkVersion 15
19 | targetSdkVersion 23
20 | versionCode 1
21 | versionName "1.0"
22 | }
23 | buildTypes {
24 | debug {
25 | signingConfig signingConfigs.release
26 | }
27 | release {
28 | signingConfig signingConfigs.release
29 | minifyEnabled true
30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 | }
34 |
35 | dependencies {
36 | compile fileTree(dir: 'libs', include: ['*.jar'])
37 | testCompile 'junit:junit:4.12'
38 | compile 'com.android.support:appcompat-v7:23.3.0'
39 | compile 'com.android.support:design:23.3.0'
40 | compile 'com.android.support:cardview-v7:23.3.0'
41 |
42 | compile 'com.jakewharton:butterknife:8.0.0'
43 | apt 'com.jakewharton:butterknife-compiler:8.0.0'
44 | compile 'com.jude:rollviewpager:1.2.9'
45 |
46 | compile 'io.reactivex:rxandroid:1.1.0'
47 | compile 'io.reactivex:rxjava:1.1.3'
48 |
49 | compile 'com.squareup.retrofit2:retrofit:2.0.2'
50 | compile 'com.squareup.retrofit2:converter-gson:2.0.2'
51 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
52 |
53 | compile 'com.squareup.okhttp3:okhttp:3.2.0'
54 | compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
55 | compile 'com.squareup.okio:okio:1.8.0'
56 |
57 |
58 | compile 'com.mcxiaoke.volley:library:1.0.19'
59 |
60 | compile 'com.squareup.picasso:picasso:2.5.2'
61 | compile 'com.facebook.fresco:fresco:0.10.0'
62 | compile 'de.hdodenhof:circleimageview:2.0.0'
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_movieinfo.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
21 |
22 |
31 |
32 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/app_bar_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
26 |
27 |
28 |
29 |
30 |
31 |
36 |
37 |
38 |
39 |
40 |
41 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/presenter/Top250PresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.presenter;
2 |
3 | import android.content.Context;
4 |
5 | import com.toryang.sampledemo.api.InitRetrofit;
6 | import com.toryang.sampledemo.api.NetService;
7 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
8 | import com.toryang.sampledemo.ui.view.TopDataView;
9 | import com.toryang.sampledemo.utils.Log;
10 |
11 | import rx.Observer;
12 | import rx.android.schedulers.AndroidSchedulers;
13 | import rx.functions.Action0;
14 | import rx.schedulers.Schedulers;
15 |
16 | /**
17 | * Created by toryang on 5/24/16.
18 | */
19 | public class Top250PresenterImpl extends BasePresenter {
20 |
21 | Log log = Log.YLog();
22 | Context context;
23 | public Top250PresenterImpl(Context context){
24 | this.context = context;
25 | }
26 |
27 | @Override
28 | public void attachView(TopDataView topDataView) {
29 | super.attachView(topDataView);
30 | }
31 |
32 | @Override
33 | public void detachView() {
34 | super.detachView();
35 | }
36 |
37 | public void getTop250(){
38 | InitRetrofit.createApi(NetService.class)
39 | .getTop250()
40 | .subscribeOn(Schedulers.io())
41 | .doOnSubscribe(new Action0() {
42 | @Override
43 | public void call() {
44 | getMvpView().startLoading();
45 | }
46 | })
47 | .observeOn(AndroidSchedulers.mainThread())
48 | .subscribe(new Observer() {
49 | @Override
50 | public void onCompleted() {
51 | getMvpView().hideLoading();
52 | }
53 |
54 | @Override
55 | public void onError(Throwable e) {
56 | log.e(e.getStackTrace());
57 | }
58 |
59 | @Override
60 | public void onNext(Movieinfo top250Entity) {
61 | getMvpView().dataBack(top250Entity);
62 | }
63 | });
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/loading/SingleBall.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.loading;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | import com.toryang.sampledemo.R;
12 |
13 | /**
14 | * Created by toryang on 5/26/16.
15 | */
16 | public class SingleBall extends View {
17 |
18 | private int width;
19 | private int height;
20 |
21 | private Paint paint;
22 |
23 | private int loadingColor = Color.BLUE;
24 |
25 |
26 | public SingleBall(Context context) {
27 | super(context);
28 | initView(null);
29 | }
30 |
31 | public SingleBall(Context context, AttributeSet attrs) {
32 | super(context, attrs);
33 | initView(attrs);
34 | }
35 |
36 | public SingleBall(Context context, AttributeSet attrs, int defStyleAttr) {
37 | super(context, attrs, defStyleAttr);
38 | initView(attrs);
39 | }
40 |
41 | private void initView(AttributeSet attrs){
42 | if (null != attrs){
43 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.SingleBall);
44 | loadingColor = typedArray.getColor(R.styleable.SingleBall_single_ball_color,Color.BLUE);
45 | typedArray.recycle();
46 | }
47 | paint = new Paint();
48 | paint.setColor(loadingColor);
49 | paint.setStyle(Paint.Style.FILL);
50 | paint.setAntiAlias(true);
51 | }
52 |
53 | @Override
54 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
55 | super.onSizeChanged(w, h, oldw, oldh);
56 | width = w;
57 | height = h;
58 | }
59 |
60 | @Override
61 | protected void onDraw(Canvas canvas) {
62 | super.onDraw(canvas);
63 | canvas.drawCircle(width/2, height/2, width/2, paint);
64 | }
65 |
66 | public void setLoadingColor(int color){
67 | loadingColor = color;
68 | paint.setColor(color);
69 | postInvalidate();
70 | }
71 |
72 | public int getLoadingColor(){
73 | return loadingColor;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/movieinfo.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class Movieinfo {
11 |
12 | @SerializedName("count")
13 | @Expose
14 | private Integer count;
15 | @SerializedName("start")
16 | @Expose
17 | private Integer start;
18 | @SerializedName("total")
19 | @Expose
20 | private Integer total;
21 |
22 | @SerializedName("subjects")
23 | @Expose
24 | private List subjects = new ArrayList();
25 | @SerializedName("title")
26 | @Expose
27 | private String title;
28 |
29 |
30 | /**
31 | *
32 | * @return
33 | * The count
34 | */
35 | public Integer getCount() {
36 | return count;
37 | }
38 |
39 | /**
40 | *
41 | * @param count
42 | * The count
43 | */
44 | public void setCount(Integer count) {
45 | this.count = count;
46 | }
47 |
48 | /**
49 | *
50 | * @return
51 | * The start
52 | */
53 | public Integer getStart() {
54 | return start;
55 | }
56 |
57 | /**
58 | *
59 | * @param start
60 | * The start
61 | */
62 | public void setStart(Integer start) {
63 | this.start = start;
64 | }
65 |
66 | /**
67 | *
68 | * @return
69 | * The total
70 | */
71 | public Integer getTotal() {
72 | return total;
73 | }
74 |
75 | /**
76 | *
77 | * @param total
78 | * The total
79 | */
80 | public void setTotal(Integer total) {
81 | this.total = total;
82 | }
83 |
84 | /**
85 | *
86 | * @return
87 | * The subjects
88 | */
89 | public List getSubjects() {
90 | return subjects;
91 | }
92 |
93 | /**
94 | *
95 | * @param subjects
96 | * The subject
97 | */
98 | public void setSubjects(List subjects) {
99 | this.subjects = subjects;
100 | }
101 |
102 | /**
103 | *
104 | * @return
105 | * The title
106 | */
107 | public String getTitle() {
108 | return title;
109 | }
110 |
111 | /**
112 | *
113 | * @param title
114 | * The title
115 | */
116 | public void setTitle(String title) {
117 | this.title = title;
118 | }
119 |
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/fragment/TopMovFragment.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.widget.GridLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.toryang.sampledemo.R;
12 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
13 | import com.toryang.sampledemo.loading.MyLoading;
14 | import com.toryang.sampledemo.presenter.Top250PresenterImpl;
15 | import com.toryang.sampledemo.ui.BaseFragment;
16 | import com.toryang.sampledemo.ui.activity.MovieInfoActivity;
17 | import com.toryang.sampledemo.ui.adapter.GridAdapter;
18 | import com.toryang.sampledemo.ui.adapter.GridItemClick;
19 | import com.toryang.sampledemo.ui.adapter.GridSpacingItemDecoration;
20 | import com.toryang.sampledemo.ui.view.TopDataView;
21 |
22 | import butterknife.BindView;
23 | import butterknife.ButterKnife;
24 |
25 | /**
26 | * Created by toryang on 16/4/27.
27 | */
28 | public class TopMovFragment extends BaseFragment implements TopDataView {
29 |
30 | @BindView(R.id.rv_movieinfo)
31 | RecyclerView rvMovieinfo;
32 | @BindView(R.id.loading)
33 | MyLoading loading;
34 |
35 | private Top250PresenterImpl presenter;
36 |
37 | @Nullable
38 | @Override
39 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
40 | View view = inflater.inflate(R.layout.activity_gridmovie, container, false);
41 | ButterKnife.bind(this, view);
42 | setMyLoading(loading);
43 | presenter = new Top250PresenterImpl(getActivity());
44 | presenter.attachView(this);
45 | presenter.getTop250();
46 | return view;
47 | }
48 |
49 | @Override
50 | public void dataBack(final Movieinfo top250Entity) {
51 | int spaceCount = 3;
52 | int spacing = 40;
53 | GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),spaceCount);
54 | rvMovieinfo.addItemDecoration(new GridSpacingItemDecoration(spaceCount,spacing,true));
55 | rvMovieinfo.setLayoutManager(gridLayoutManager);
56 | rvMovieinfo.setHasFixedSize(true);
57 | GridAdapter adapter = new GridAdapter(getActivity(),top250Entity);
58 | rvMovieinfo.setAdapter(adapter);
59 | rvMovieinfo.addOnItemTouchListener(new GridItemClick(getActivity(), new GridItemClick.OnItemClickListener() {
60 | @Override
61 | public void onItemClick(View view, int position) {
62 | MovieInfoActivity.startActivity(getActivity(),top250Entity.getSubjects().get(position));
63 | }
64 | }));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/.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 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/activity/MovieInfoActivity.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.activity;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.design.widget.CollapsingToolbarLayout;
8 | import android.support.v7.widget.Toolbar;
9 | import android.view.MenuItem;
10 | import android.widget.ImageView;
11 |
12 | import com.squareup.picasso.Picasso;
13 | import com.toryang.sampledemo.App;
14 | import com.toryang.sampledemo.R;
15 |
16 | import com.toryang.sampledemo.entities.movieEntitiy.Subject;
17 | import com.toryang.sampledemo.entities.usbox.Subject_;
18 | import com.toryang.sampledemo.ui.BaseActivity;
19 |
20 | import butterknife.BindView;
21 | import butterknife.ButterKnife;
22 |
23 | /**
24 | * Created by toryang on 5/25/16.
25 | */
26 | public class MovieInfoActivity extends BaseActivity {
27 |
28 |
29 | public static Subject_ mUsBoxSubject;
30 | public static Subject subject;
31 |
32 | Picasso picasso = App.getPicasso();
33 |
34 |
35 | public static void startActivity(Context context, Subject_ usBoxSubject) {
36 | mUsBoxSubject = usBoxSubject;
37 | Intent intent = new Intent(context, MovieInfoActivity.class);
38 | context.startActivity(intent);
39 | }
40 |
41 | public static void startActivity(Context context, Subject movieSubject) {
42 | subject = movieSubject;
43 | Intent intent = new Intent(context, MovieInfoActivity.class);
44 | context.startActivity(intent);
45 | }
46 |
47 |
48 |
49 | @BindView(R.id.image)
50 | ImageView image;
51 | @BindView(R.id.collapsing_toolbar)
52 | CollapsingToolbarLayout collapsingToolbar;
53 | @BindView(R.id.toolbar)
54 | Toolbar toolbar;
55 |
56 | @Override
57 | protected void onCreate(@Nullable Bundle savedInstanceState) {
58 | super.onCreate(savedInstanceState);
59 | setContentView(R.layout.activity_movieinfo);
60 | ButterKnife.bind(this);
61 | operateView();
62 | }
63 |
64 | @Override
65 | public void operateView() {
66 | setSupportActionBar(toolbar);
67 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
68 | if (mUsBoxSubject != null){
69 | collapsingToolbar.setTitle(mUsBoxSubject.getTitle());
70 | picasso.with(this).load(mUsBoxSubject.getImages().getLarge()).into(image);
71 | }else {
72 | collapsingToolbar.setTitle(subject.getTitle());
73 | picasso.with(this).load(subject.getImages().getLarge()).into(image);
74 | }
75 |
76 | }
77 | @Override
78 | public boolean onOptionsItemSelected(MenuItem item) {
79 | switch (item.getItemId()){
80 | case android.R.id.home:
81 | onBackPressed();
82 | break;
83 | }
84 | return true;
85 | }
86 |
87 | @Override
88 | protected void onDestroy() {
89 | super.onDestroy();
90 | mUsBoxSubject = null;
91 | subject = null;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/adapter/LoopAdapter.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.drawable.BitmapDrawable;
6 | import android.graphics.drawable.Drawable;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 |
11 | import com.jude.rollviewpager.RollPagerView;
12 | import com.jude.rollviewpager.adapter.LoopPagerAdapter;
13 | import com.toryang.sampledemo.R;
14 | import com.toryang.sampledemo.common.OkhttpUtil;
15 | import com.toryang.sampledemo.utils.Log;
16 |
17 | import java.io.IOException;
18 |
19 | import rx.Observable;
20 | import rx.Subscriber;
21 | import rx.android.schedulers.AndroidSchedulers;
22 | import rx.schedulers.Schedulers;
23 |
24 | /**
25 | * Created by toryang on 16/4/26.
26 | */
27 | public class LoopAdapter extends LoopPagerAdapter {
28 | Log log = Log.YLog();
29 | private int[] imgs = {
30 | R.drawable.img1,
31 | R.drawable.img2,
32 | R.drawable.img3,
33 | R.drawable.img4,
34 | R.drawable.img5
35 | };
36 | private String[] imageUri;
37 | Context context;
38 |
39 | public LoopAdapter(Context context,RollPagerView viewPager, String[] imageUri) {
40 | super(viewPager);
41 | this.context = context;
42 | this.imageUri = imageUri;
43 | }
44 |
45 | @Override
46 | public View getView(ViewGroup container, int position) {
47 | ImageView view = new ImageView(container.getContext());
48 | view.setImageResource(imgs[position]);
49 | // log.d(imageUri[position]);
50 | // downLoadImage(new OkhttpUtil(imageUri[position]).downloadDrawble);
51 | // view.setImageDrawable(downLoadImage(new OkhttpUtil(imageUri[position]).downloadDrawble));
52 | view.setScaleType(ImageView.ScaleType.CENTER_CROP);
53 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
54 | return view;
55 | }
56 |
57 | @Override
58 | protected int getRealCount() {
59 | return imageUri.length;
60 | }
61 |
62 |
63 | public Drawable downLoadImage(Observable observable){
64 | final Drawable[] drawables = {null};
65 | observable.subscribeOn(Schedulers.io())
66 | .observeOn(AndroidSchedulers.mainThread())
67 | .subscribe(new Subscriber() {
68 | @Override
69 | public void onCompleted() {
70 |
71 | }
72 |
73 | @Override
74 | public void onError(Throwable e) {
75 | log.e(e.toString());
76 | }
77 |
78 | @Override
79 | public void onNext(Bitmap bitmap) {
80 | Drawable drawable = new BitmapDrawable(context.getResources(),bitmap);
81 | drawables[0] =drawable;
82 | }
83 | });
84 |
85 | return drawables[0];
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/adapter/GridAdapter.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.support.v7.widget.CardView;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 |
12 | import com.facebook.drawee.view.SimpleDraweeView;
13 | import com.toryang.sampledemo.R;
14 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
15 | import com.toryang.sampledemo.entities.usbox.UsBoxEntity;
16 | import com.toryang.sampledemo.utils.Log;
17 |
18 | import butterknife.BindView;
19 | import butterknife.ButterKnife;
20 |
21 | /**
22 | * Created by toryang on 5/24/16.
23 | */
24 | public class GridAdapter extends RecyclerView.Adapter {
25 |
26 | Log log = Log.YLog();
27 | private Context mContext;
28 |
29 | private UsBoxEntity usBoxEntity;
30 | private Movieinfo movieinfo;
31 |
32 | public GridAdapter(Context context, Movieinfo movieinfo){
33 | mContext = context ;
34 | this.movieinfo = movieinfo;
35 | }
36 | public GridAdapter(Context context,UsBoxEntity usBoxEntity){
37 | mContext = context;
38 | this.usBoxEntity = usBoxEntity;
39 | }
40 |
41 | @Override
42 | public GridViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
43 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_movie,null);
44 | GridViewHolder gridViewHolder = new GridViewHolder(view);
45 | return gridViewHolder;
46 | }
47 |
48 | @Override
49 | public void onBindViewHolder(GridViewHolder holder, int position) {
50 | // log.d(position);
51 | if (usBoxEntity !=null){
52 | // App.getPicasso().with(mContext).load(usBoxEntity.getSubjects().get(position).getSubject().getImages().getLarge()).into(holder.imageView);
53 | holder.simpleDraweeView.setImageURI(getUri(usBoxEntity.getSubjects().get(position).getSubject().getImages().getLarge()));
54 | holder.textView.setText(usBoxEntity.getSubjects().get(position).getSubject().getTitle());
55 | }else{
56 | // App.getPicasso().with(mContext).load(top250Entity.getSubjects().get(position).getImages().getLarge()).into(holder.imageView);
57 | holder.simpleDraweeView.setImageURI(getUri(movieinfo.getSubjects().get(position).getImages().getLarge()));
58 | holder.textView.setText(movieinfo.getSubjects().get(position).getTitle());
59 | }
60 | }
61 |
62 | @Override
63 | public int getItemCount() {
64 | return usBoxEntity!=null ? usBoxEntity.getSubjects().size():movieinfo.getSubjects().size();
65 | }
66 |
67 | public class GridViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
68 |
69 | @BindView(R.id.rl_cardview)
70 | CardView mRlCardview;
71 | @BindView(R.id.image_movie)
72 | SimpleDraweeView simpleDraweeView;
73 | @BindView(R.id.tv_movie_name)
74 | TextView textView;
75 |
76 | public GridViewHolder(View itemView) {
77 | super(itemView);
78 | ButterKnife.bind(this,itemView);
79 | }
80 |
81 | @Override
82 | public void onClick(View v) {
83 | if (v.getId() == R.id.rl_cardview){
84 | log.d(getPosition());
85 | }
86 |
87 | }
88 | }
89 |
90 | private Uri getUri(String uri){
91 | return Uri.parse(uri);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/activity/GridMovieActivity.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.activity;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.widget.GridLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 |
12 | import com.toryang.sampledemo.R;
13 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
14 | import com.toryang.sampledemo.entities.usbox.UsBoxEntity;
15 | import com.toryang.sampledemo.ui.BaseActivity;
16 | import com.toryang.sampledemo.ui.adapter.GridAdapter;
17 | import com.toryang.sampledemo.ui.adapter.GridItemClick;
18 | import com.toryang.sampledemo.ui.adapter.GridSpacingItemDecoration;
19 | import com.toryang.sampledemo.utils.Log;
20 |
21 | import butterknife.BindArray;
22 | import butterknife.BindView;
23 | import butterknife.ButterKnife;
24 |
25 | /**
26 | * Created by toryang on 5/24/16.
27 | */
28 | public class GridMovieActivity extends BaseActivity {
29 |
30 | Log log = Log.YLog();
31 |
32 | public static UsBoxEntity mUsBoxEntity;
33 | public static Movieinfo mMovieinfo;
34 |
35 | @BindView(R.id.rv_movieinfo)
36 | RecyclerView rvMovieinfo;
37 | @BindArray(R.array.movie_title)
38 | String[] movie;
39 |
40 | public static void startActivity(Context context, UsBoxEntity usBoxEntity) {
41 | mUsBoxEntity = usBoxEntity;
42 | Intent intent = new Intent(context, GridMovieActivity.class);
43 | context.startActivity(intent);
44 | }
45 |
46 | public static void startActivity(Context context, Movieinfo movieinfo) {
47 | mMovieinfo = movieinfo;
48 | Intent intent = new Intent(context, GridMovieActivity.class);
49 | context.startActivity(intent);
50 | }
51 | @Override
52 | protected void onCreate(@Nullable Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | setContentView(R.layout.activity_gridmovie);
55 | ButterKnife.bind(this);
56 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
57 | operateView();
58 | }
59 |
60 | @Override
61 | protected void onResume() {
62 | super.onResume();
63 | }
64 |
65 | @Override
66 | public void operateView() {
67 | int spanCount = 3;
68 | int spacing = 30;
69 | GridLayoutManager gridLayoutManager = new GridLayoutManager(this,spanCount);
70 | rvMovieinfo.setLayoutManager(gridLayoutManager);
71 | rvMovieinfo.addItemDecoration(new GridSpacingItemDecoration(spanCount,spacing,true ));
72 | rvMovieinfo.setHasFixedSize(true);
73 | final GridAdapter gridAdapter;
74 |
75 | if (mUsBoxEntity != null) {
76 | gridAdapter= new GridAdapter(this,mUsBoxEntity);
77 | getSupportActionBar().setTitle(mUsBoxEntity.getTitle());
78 | } else {
79 | gridAdapter = new GridAdapter(this,mMovieinfo);
80 | getSupportActionBar().setTitle(mMovieinfo.getTitle());
81 | }
82 | rvMovieinfo.setAdapter(gridAdapter);
83 | rvMovieinfo.addOnItemTouchListener(new GridItemClick(this,new GridItemClick.OnItemClickListener(){
84 | @Override
85 | public void onItemClick(View view, int position) {
86 | if (mUsBoxEntity != null) {
87 | MovieInfoActivity.startActivity(GridMovieActivity.this,mUsBoxEntity.getSubjects().get(position).getSubject());
88 | } else {
89 | MovieInfoActivity.startActivity(GridMovieActivity.this,mMovieinfo.getSubjects().get(position));
90 | }
91 | }
92 | })
93 | );
94 | }
95 |
96 |
97 | @Override
98 | public boolean onOptionsItemSelected(MenuItem item) {
99 | switch (item.getItemId()){
100 | case android.R.id.home:
101 | finish();
102 | break;
103 | }
104 | return true;
105 | }
106 |
107 | @Override
108 | protected void onDestroy() {
109 | super.onDestroy();
110 | mUsBoxEntity = null;
111 | mMovieinfo = null;
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/common/OkhttpUtil.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.common;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Environment;
7 |
8 | import com.toryang.sampledemo.utils.Log;
9 |
10 | import java.io.File;
11 | import java.io.FileOutputStream;
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.io.OutputStream;
15 | import java.util.Collections;
16 |
17 | import okhttp3.OkHttpClient;
18 | import okhttp3.Protocol;
19 | import okhttp3.Request;
20 | import okhttp3.Response;
21 | import rx.Observable;
22 | import rx.Subscriber;
23 | import rx.android.schedulers.AndroidSchedulers;
24 | import rx.functions.Action1;
25 | import rx.schedulers.Schedulers;
26 |
27 | /**
28 | * Created by toryang on 5/15/16.
29 | */
30 | public class OkhttpUtil {
31 | Log log = Log.YLog();
32 | String url;
33 | public OkhttpUtil(String url){
34 | this.url = url;
35 | }
36 | public void run() throws IOException{
37 | OkHttpClient client = new OkHttpClient();
38 | Request request = new Request.Builder()
39 | .url(url)
40 | .build();
41 | Response response = client.newCall(request).execute();
42 |
43 | log.d(response.body().string());
44 | }
45 |
46 |
47 |
48 | /**
49 | * download bitmap image;
50 | */
51 | public Observable downloadDrawble = Observable.create(new Observable.OnSubscribe() {
52 | @Override
53 | public void call(Subscriber super Bitmap> subscriber) {
54 | OkHttpClient client = new OkHttpClient();
55 | Request request = new Request.Builder()
56 | .url(url)
57 | .build();
58 |
59 | try {
60 | Response response = client.newCall(request).execute();
61 | if (response.isSuccessful()){
62 | InputStream input = response.body().byteStream();
63 | Bitmap bitmap = BitmapFactory.decodeStream(input);
64 | subscriber.onNext(bitmap);
65 | }
66 | }catch (IOException e){
67 | subscriber.onError(e);
68 | }
69 | }
70 | });
71 |
72 |
73 | File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
74 | File file = new File(path,"/pathtofile");
75 |
76 | /**
77 | * download file with OkHttp and RxJava (rate)
78 | */
79 | public Observable downloadObservable = Observable.create(new Observable.OnSubscribe() {
80 | @Override
81 | public void call(Subscriber super String> subscriber) {
82 | InputStream inputStream = null;
83 | OutputStream outputStream = null;
84 | OkHttpClient client = new OkHttpClient();
85 | Request request = new Request.Builder()
86 | .url(url)
87 | .build();
88 | try{
89 | Response response = client.newCall(request).execute();
90 | if (response.isSuccessful()){
91 | inputStream = response.body().byteStream();
92 | long length = response.body().contentLength();
93 | outputStream = new FileOutputStream(file);
94 | byte data[] = new byte[1024];
95 | subscriber.onNext("0%");
96 | long total = 0;
97 | int count;
98 | while ((count = inputStream.read(data)) != -1){
99 | total += count;
100 | subscriber.onNext(String.valueOf(total*100/length) + "%");
101 | outputStream.write(data,0,count);
102 | }
103 | outputStream.flush();
104 | outputStream.close();
105 | inputStream.close();
106 |
107 | }
108 |
109 | }catch (IOException e){
110 | subscriber.onError(e);
111 | }finally {
112 | if (inputStream != null){
113 | try{
114 | inputStream.close();
115 | }catch (IOException e){}
116 | }
117 | if (outputStream != null){
118 | try {
119 | outputStream.close();
120 | }catch (IOException e){}
121 | }
122 | }
123 | subscriber.onCompleted();
124 | }
125 | });
126 | }
127 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/fragment/HotMovieFragment.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.fragment;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.drawable.BitmapDrawable;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.ImageView;
13 |
14 | import com.toryang.sampledemo.R;
15 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
16 | import com.toryang.sampledemo.entities.usbox.UsBoxEntity;
17 | import com.toryang.sampledemo.loading.MyLoading;
18 | import com.toryang.sampledemo.presenter.HotMoviePresenterImpl;
19 | import com.toryang.sampledemo.ui.BaseFragment;
20 | import com.toryang.sampledemo.ui.adapter.OutRecyclerAdapter;
21 | import com.toryang.sampledemo.ui.view.DataView;
22 | import com.toryang.sampledemo.utils.Log;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | import butterknife.BindArray;
28 | import butterknife.BindView;
29 | import butterknife.ButterKnife;
30 | import rx.Observable;
31 | import rx.Subscriber;
32 | import rx.android.schedulers.AndroidSchedulers;
33 | import rx.schedulers.Schedulers;
34 |
35 | /**
36 | * Created by toryang on 16/4/26.
37 | */
38 | public class HotMovieFragment extends BaseFragment implements DataView {
39 |
40 | @BindView(R.id.recycler_movie)
41 | RecyclerView recyclerMovie;
42 | @BindView(R.id.loading)
43 | MyLoading loading;
44 |
45 | @BindArray(R.array.movie_title)
46 | String[] title;
47 |
48 |
49 | private HotMoviePresenterImpl presenter;
50 | private OutRecyclerAdapter mAdapter;
51 |
52 | List