datas) {
58 | this.datas = datas;
59 | }
60 |
61 | public static class DatasBean {
62 | private String uid;
63 | private String avatar;
64 |
65 | public String getUid() {
66 | return uid;
67 | }
68 |
69 | public void setUid(String uid) {
70 | this.uid = uid;
71 | }
72 |
73 | public String getAvatar() {
74 | return avatar;
75 | }
76 |
77 | public void setAvatar(String avatar) {
78 | this.avatar = avatar;
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/model/entity/Recommend.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.model.entity;
2 |
3 | /**
4 | * Created by Mr.Yangxiufeng
5 | * DATE 2016/8/26
6 | * owspace
7 | */
8 | public class Recommend {
9 |
10 | /**
11 | * id : 292607
12 | * uid : 282018
13 | * thumbnail : http://img.owspace.com/Public/uploads/Picture/2016-08-25/57beba52b6c42.jpg
14 | * status : 1
15 | * share : http://static.owspace.com/wap/292607.html
16 | * html : http://static.owspace.com/wap/292607.html
17 | */
18 | private String id;
19 | private String uid;
20 | private String thumbnail;
21 | private String status;
22 | private String share;
23 | private String html;
24 |
25 | public String getId() {
26 | return id;
27 | }
28 |
29 | public void setId(String id) {
30 | this.id = id;
31 | }
32 |
33 | public String getUid() {
34 | return uid;
35 | }
36 |
37 | public void setUid(String uid) {
38 | this.uid = uid;
39 | }
40 |
41 | public String getThumbnail() {
42 | return thumbnail;
43 | }
44 |
45 | public void setThumbnail(String thumbnail) {
46 | this.thumbnail = thumbnail;
47 | }
48 |
49 | public String getStatus() {
50 | return status;
51 | }
52 |
53 | public void setStatus(String status) {
54 | this.status = status;
55 | }
56 |
57 | public String getShare() {
58 | return share;
59 | }
60 |
61 | public void setShare(String share) {
62 | this.share = share;
63 | }
64 |
65 | public String getHtml() {
66 | return html;
67 | }
68 |
69 | public void setHtml(String html) {
70 | this.html = html;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/model/entity/Result.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.model.entity;
2 |
3 | /**
4 | * Created by Mr.Yangxiufeng
5 | * DATE 2016/7/21
6 | * owspace
7 | */
8 | public class Result {
9 |
10 | /**
11 | * status : ok
12 | * datas : {"id":"292296","uid":"2132","name":"","title":"一位演员也是\r\n一个世界","excerpt":"耀眼的光环总让我们以为明星都是空洞的,而姚晨却以某种平民精神,试图理解世界、观察自身。本期\u201c十三邀\u201d,许知远专访姚晨。","lead":"腾讯新闻和单向空间联合出品的谈话节目《十三邀》,是许知远对这个时代所做的新思考。这是第二期。在这一期,姚晨来到位于北京花家地的单向空间,用她自己的话说,这是许知远的\u201c地盘\u201d。长达四个小时的对话,他们都聊了什么?","model":"2","position":"0","thumbnail":"http://img.owspace.com/Public/uploads/Picture/2016-07-13/5785d02bd885f.jpg","create_time":"1468388678","update_time":"2016/07/13","video":"http://img.owspace.com/V_poa248777_1468383459.0986272.mp4","fm":"","link_url":"","view":"7.6w","share":"http://static.owspace.com/wap/292296.html","comment":"89","good":"161","bookmark":"0","fm_play":"","content":"\u201c我觉得我们都挺容易去概念化地理解一个人。\u201d许知远在采访后回忆。他以对娱乐明星\u201c空洞\u201d的代入感开始,到同姚晨共话黑泽明笔下的\u201c蛤蟆油\u201d;以姚晨穿着的那双小白鞋为初印象,到头脑中反复回旋着曾经小镇姑娘式的生活,可以说,他在头脑中已经重新透视了姚晨所代表的文化符号。这一过程,也许你认为是许知远的偏见,其实,是我们每个人的偏见。
<\/p>
主持人:<\/h2>
许知远,作家,单向空间联合创始人。2000 年毕业于北京大学计算机系。曾任《经济观察报》主笔、《商业周刊/中文版》执行主编。已出版作品《那些忧伤的年轻人》《一个游荡者的世界》《祖国的陌生人》等。<\/p>
<\/p>
第二期嘉宾:<\/h2>
姚晨,中国内地女演员,联合国难民署中国亲善大使。第 2 届华鼎奖电视剧盛典最佳女主角,第 18 届北京大学生电影节最受欢迎女演员,代表作有《武林外传》《潜伏》《离婚律师》等。2013 年、2014 年入围美国《时代》周刊\u201c全球 100 位最具影响力人物\u201d,2014 年当选;2015 年入围该杂志评选的\u201c全球 30 位最具网络影响力人物\u201d;倍耐力年历首位华人封面。2016 年世界经济论坛水晶奖获得者,也是首位获得该奖项的华人女性; 2016 年世界经济论坛\u201c全球青年领袖\u201d中国唯一入选女星。<\/p>
<\/p>
\u201c过去十年,还有一个重要的问题是平民的兴起,平民从来没有获得过这样的一次表达机会,而姚晨身上具有某种平民精神,同时她又理解自己是怎么回事。\u201c许知远在第二期《十三邀》中这样总结。的确,在被科技引领的今天,每一个人都有可能在下一秒被千万人聆听,这是属于普通人的特别时代。<\/p>
许知远说,他是一个不太靠谱的作家,试图捕捉时代的精神,却又常常厌恶时代的流行情绪;他也是一个勉强的创业者,努力获得商业上的成功,却又不完全相信商业的逻辑。这个时代在他眼中,有着过分娱乐化和浅薄的一面,所以,他试图寻找一种方式,打破大家思维中的惯性,同时,他也希望了解这个时代中,新的动力、情绪和人们的内心世界。<\/p>
于是,腾讯新闻联合单向空间,寻找了 13 位在一定意义上来说具有模板作用的个人,向他们发出邀请,希望通过访谈的形式,观察他们的行为,分享他们的经验和心得。从正在发生的样本出发,探求中国发展的切片。<\/p>
<\/p>
<\/p>","template":"","link_id":"0","extend":null,"parseXML":1,"html5":"http://static.owspace.com/wap/292296.html","author":"单读视频","tpl":2,"avatar":"http://img.owspace.com/Public/static/avatar/4.png","category":"TO WATCH","hot_comments":[]}
13 | * msg :
14 | * code : 0
15 | */
16 |
17 | private String status;
18 | private String msg;
19 | private int code;
20 |
21 | public static class Data extends Result{
22 | private T datas;
23 |
24 | public T getDatas() {
25 | return datas;
26 | }
27 |
28 | public void setDatas(T datas) {
29 | this.datas = datas;
30 | }
31 | }
32 |
33 | public String getStatus() {
34 | return status;
35 | }
36 |
37 | public void setStatus(String status) {
38 | this.status = status;
39 | }
40 |
41 | public String getMsg() {
42 | return msg;
43 | }
44 |
45 | public void setMsg(String msg) {
46 | this.msg = msg;
47 | }
48 |
49 | public int getCode() {
50 | return code;
51 | }
52 |
53 | public void setCode(int code) {
54 | this.code = code;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/model/entity/SplashEntity.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.model.entity;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by Mr.Yangxiufeng
7 | * DATE 2016/7/21
8 | * owspace
9 | */
10 | public class SplashEntity {
11 |
12 | /**
13 | * status : ok
14 | * time : 1468154610
15 | * images : ["http://img.owspace.com/Public/uploads/Picture/2016-07-10/578242d91d113.jpg","http://img.owspace.com/Public/uploads/Picture/2016-07-10/578242d62ce5f.jpg","http://img.owspace.com/Public/uploads/Picture/2016-07-10/578242d2e6e61.jpg","http://img.owspace.com/Public/uploads/Picture/2016-07-10/578242d0468b1.jpg","http://img.owspace.com/Public/uploads/Picture/2016-07-10/578242cada2b5.jpg","http://img.owspace.com/Public/uploads/Picture/2016-07-10/578242c7198d2.jpg","http://img.owspace.com/Public/uploads/Picture/2016-07-07/577dbb32d1ca9.jpg","http://img.owspace.com/Public/uploads/Picture/2016-07-05/577b1fcd65e2a.jpg"]
16 | * count : 8
17 | */
18 |
19 | private String status;
20 | private int time;
21 | private int count;
22 | private List images;
23 |
24 | public String getStatus() {
25 | return status;
26 | }
27 |
28 | public void setStatus(String status) {
29 | this.status = status;
30 | }
31 |
32 | public int getTime() {
33 | return time;
34 | }
35 |
36 | public void setTime(int time) {
37 | this.time = time;
38 | }
39 |
40 | public int getCount() {
41 | return count;
42 | }
43 |
44 | public void setCount(int count) {
45 | this.count = count;
46 | }
47 |
48 | public List getImages() {
49 | return images;
50 | }
51 |
52 | public void setImages(List images) {
53 | this.images = images;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/model/util/DateTimeTypeAdapter.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.model.util;
2 |
3 | import com.google.gson.JsonDeserializationContext;
4 | import com.google.gson.JsonDeserializer;
5 | import com.google.gson.JsonElement;
6 | import com.google.gson.JsonParseException;
7 | import com.google.gson.JsonPrimitive;
8 | import com.google.gson.JsonSerializationContext;
9 | import com.google.gson.JsonSerializer;
10 |
11 | import org.joda.time.DateTime;
12 |
13 | import java.lang.reflect.Type;
14 |
15 | public class DateTimeTypeAdapter implements JsonSerializer, JsonDeserializer {
16 |
17 | @Override
18 | public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context) {
19 | return new JsonPrimitive(src.toString());
20 | }
21 |
22 | @Override
23 | public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
24 | return new DateTime(json.getAsString());
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/model/util/EntityUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.model.util;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.GsonBuilder;
5 |
6 | import org.joda.time.DateTime;
7 |
8 | public final class EntityUtils {
9 |
10 | private EntityUtils() {}
11 |
12 | public static final Gson gson = new GsonBuilder()
13 | .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter())
14 | .create();
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/model/util/HttpUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.model.util;
2 |
3 | import com.github.baby.owspace.BuildConfig;
4 |
5 | import java.util.concurrent.TimeUnit;
6 |
7 | import okhttp3.OkHttpClient;
8 | import okhttp3.logging.HttpLoggingInterceptor;
9 |
10 | /**
11 | * Created by Mr.Yangxiufeng
12 | * DATE 2016/7/21
13 | * Owspace
14 | */
15 | public class HttpUtils {
16 | private HttpUtils() {}
17 | public static final OkHttpClient client = new OkHttpClient.Builder()
18 | .connectTimeout(20, TimeUnit.SECONDS)
19 | .readTimeout(20,TimeUnit.SECONDS)
20 | .addInterceptor(createHttpLoggingInterceptor())
21 | .build();
22 |
23 | private static HttpLoggingInterceptor createHttpLoggingInterceptor() {
24 | HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
25 | loggingInterceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
26 | return loggingInterceptor;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/player/IPlayback.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.player;
2 |
3 | import android.support.annotation.Nullable;
4 |
5 | /**
6 | * Created by Mr.Yangxiufeng
7 | * DATE 2016/11/14
8 | * owspace
9 | */
10 |
11 | public interface IPlayback {
12 |
13 | boolean play();
14 |
15 | boolean play(String song);
16 |
17 | boolean pause();
18 |
19 | boolean isPlaying();
20 |
21 | int getProgress();
22 |
23 | int getDuration();
24 |
25 | boolean seekTo(int progress);
26 |
27 | void registerCallback(Callback callback);
28 |
29 | void unregisterCallback(Callback callback);
30 |
31 | void removeCallbacks();
32 |
33 | void releasePlayer();
34 |
35 | interface Callback {
36 |
37 | void onComplete(PlayState state);
38 |
39 | void onPlayStatusChanged(PlayState status);
40 |
41 | void onPosition(int position);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/player/MediaPlayController.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.player;
2 |
3 | /**
4 | * Created by Mr.Yangxiufeng
5 | * DATE 2016/11/24
6 | * owspace
7 | */
8 |
9 | public class MediaPlayController {
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/player/PlayState.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.player;
2 |
3 | /**
4 | * Created by Mr.Yangxiufeng
5 | * DATE 2016/11/24
6 | * owspace
7 | */
8 |
9 | public enum PlayState {
10 | INIT,
11 | PREPARE,
12 | PLAYING,
13 | PAUSE,
14 | COMPLETE,
15 | ERROR
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/player/Player.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.player;
2 |
3 | import android.media.MediaPlayer;
4 | import android.os.Handler;
5 | import android.os.Message;
6 |
7 | import com.orhanobut.logger.Logger;
8 |
9 | import java.io.IOException;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import java.util.TimerTask;
13 |
14 | /**
15 | * Created by Mr.Yangxiufeng
16 | * DATE 2016/11/14
17 | * owspace
18 | */
19 |
20 | public class Player implements IPlayback,MediaPlayer.OnCompletionListener,MediaPlayer.OnBufferingUpdateListener,MediaPlayer.OnPreparedListener,MediaPlayer.OnErrorListener{
21 |
22 | private static volatile Player sInstance;
23 | private MediaPlayer mPlayer;
24 | private List mCallbacks = new ArrayList<>(2);
25 | private boolean isPaused;
26 | private String song;
27 |
28 | private Player() {
29 | mPlayer = new MediaPlayer();
30 | mPlayer.setOnCompletionListener(this);
31 | mPlayer.setOnPreparedListener(this);
32 | mPlayer.setOnBufferingUpdateListener(this);
33 | }
34 |
35 | public static Player getInstance() {
36 | if (sInstance == null) {
37 | synchronized (Player.class) {
38 | if (sInstance == null) {
39 | sInstance = new Player();
40 | }
41 | }
42 | }
43 | return sInstance;
44 | }
45 | @Override
46 | public boolean play() {
47 | if (isPaused){
48 | mPlayer.start();
49 | notifyPlayStatusChanged(PlayState.PLAYING);
50 | return true;
51 | }
52 | return false;
53 | }
54 |
55 | @Override
56 | public boolean play(String song) {
57 | try {
58 | mPlayer.reset();
59 | mPlayer.setDataSource(song);
60 | mPlayer.prepare();
61 | this.song = song;
62 | notifyPlayStatusChanged(PlayState.PLAYING);
63 | return true;
64 | } catch (IOException e) {
65 | notifyPlayStatusChanged(PlayState.ERROR);
66 | e.printStackTrace();
67 | }
68 | return false;
69 | }
70 |
71 | @Override
72 | public boolean pause() {
73 | if (mPlayer.isPlaying()) {
74 | mPlayer.pause();
75 | isPaused = true;
76 | notifyPlayStatusChanged(PlayState.PAUSE);
77 | return true;
78 | }
79 | return false;
80 | }
81 |
82 | @Override
83 | public boolean isPlaying() {
84 | return mPlayer.isPlaying();
85 | }
86 |
87 | @Override
88 | public int getProgress() {
89 | return mPlayer.getCurrentPosition();
90 | }
91 |
92 | @Override
93 | public int getDuration() {
94 | return mPlayer.getDuration();
95 | }
96 |
97 | @Override
98 | public boolean seekTo(int progress) {
99 | try {
100 | mPlayer.seekTo(progress);
101 | } catch (IllegalStateException e) {
102 | e.printStackTrace();
103 | }
104 | return true;
105 | }
106 |
107 | @Override
108 | public void registerCallback(Callback callback) {
109 | mCallbacks.add(callback);
110 | }
111 |
112 | @Override
113 | public void unregisterCallback(Callback callback) {
114 | mCallbacks.remove(callback);
115 | }
116 |
117 | @Override
118 | public void removeCallbacks() {
119 | mCallbacks.clear();
120 | }
121 |
122 | @Override
123 | public void releasePlayer() {
124 | mPlayer.reset();
125 | mPlayer.release();
126 | mPlayer = null;
127 | sInstance = null;
128 | song = null;
129 | }
130 |
131 | private void notifyPlayStatusChanged(PlayState status) {
132 | for (Callback callback : mCallbacks) {
133 | callback.onPlayStatusChanged(status);
134 | }
135 | }
136 | private void notifyComplete(PlayState state) {
137 | for (Callback callback : mCallbacks) {
138 | callback.onComplete(state);
139 | }
140 | }
141 |
142 | public String getSong() {
143 | return song;
144 | }
145 |
146 | @Override
147 | public void onBufferingUpdate(MediaPlayer mp, int percent) {
148 | // Logger.d("onBufferingUpdate");
149 | }
150 |
151 | @Override
152 | public void onPrepared(MediaPlayer mp) {
153 | Logger.d("onPrepared");
154 | mPlayer.start();
155 | notifyPlayStatusChanged(PlayState.PLAYING);
156 | }
157 | @Override
158 | public void onCompletion(MediaPlayer mp) {
159 | Logger.d("onCompletion");
160 | mPlayer.reset();
161 | notifyComplete(PlayState.COMPLETE);
162 | }
163 |
164 | @Override
165 | public boolean onError(MediaPlayer mp, int what, int extra) {
166 | notifyPlayStatusChanged(PlayState.ERROR);
167 | return false;
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/presenter/ArticalContract.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.presenter;
2 |
3 | import com.github.baby.owspace.model.entity.Item;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by Mr.Yangxiufeng
9 | * DATE 2016/8/2
10 | * owspace
11 | */
12 | public interface ArticalContract {
13 | interface Presenter{
14 | void getListByPage(int page, int model, String pageId,String deviceId,String createTime);
15 | }
16 | interface View{
17 | void showLoading();
18 | void dismissLoading();
19 | void showNoData();
20 | void showNoMore();
21 | void updateListUI(List- itemList);
22 | void showOnFailure();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/presenter/ArticalPresenter.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.presenter;
2 |
3 | import com.github.baby.owspace.model.api.ApiService;
4 | import com.github.baby.owspace.model.entity.Item;
5 | import com.github.baby.owspace.model.entity.Result;
6 | import com.github.baby.owspace.util.TimeUtil;
7 |
8 | import java.util.List;
9 |
10 | import javax.inject.Inject;
11 |
12 | import rx.Subscriber;
13 | import rx.android.schedulers.AndroidSchedulers;
14 | import rx.schedulers.Schedulers;
15 |
16 | /**
17 | * Created by Mr.Yangxiufeng
18 | * DATE 2016/8/3
19 | * owspace
20 | */
21 | public class ArticalPresenter implements ArticalContract.Presenter{
22 |
23 | private ArticalContract.View view;
24 | private ApiService apiService;
25 | @Inject
26 | public ArticalPresenter(ArticalContract.View view,ApiService apiService) {
27 | this.view = view;
28 | this.apiService = apiService;
29 | }
30 |
31 | @Override
32 | public void getListByPage(int page, int model, String pageId, String deviceId, String createTime) {
33 | apiService.getList("api","getList",page,model,pageId,createTime,"android","1.3.0", TimeUtil.getCurrentSeconds(), deviceId,1)
34 | .subscribeOn(Schedulers.io())
35 | .observeOn(AndroidSchedulers.mainThread())
36 | .subscribe(new Subscriber>>() {
37 | @Override
38 | public void onCompleted() {
39 |
40 | }
41 |
42 | @Override
43 | public void onError(Throwable e) {
44 | view.showOnFailure();
45 | }
46 |
47 | @Override
48 | public void onNext(Result.Data
> listData) {
49 | int size = listData.getDatas().size();
50 | if(size>0){
51 | view.updateListUI(listData.getDatas());
52 | }else {
53 | view.showNoMore();
54 | }
55 | }
56 | });
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/presenter/DetailContract.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.presenter;
2 |
3 | import com.github.baby.owspace.model.entity.DetailEntity;
4 |
5 | /**
6 | * Created by Mr.Yangxiufeng
7 | * DATE 2016/8/9
8 | * owspace
9 | */
10 | public interface DetailContract {
11 | interface Presenter{
12 | void getDetail(String itemId);
13 | }
14 | interface View{
15 | void showLoading();
16 | void dismissLoading();
17 | void updateListUI(DetailEntity detailEntity);
18 | void showOnFailure();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/presenter/DetailPresenter.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.presenter;
2 |
3 |
4 | import com.github.baby.owspace.model.api.ApiService;
5 | import com.github.baby.owspace.model.entity.DetailEntity;
6 | import com.github.baby.owspace.model.entity.Result;
7 |
8 | import javax.inject.Inject;
9 |
10 | import rx.Subscriber;
11 | import rx.android.schedulers.AndroidSchedulers;
12 | import rx.schedulers.Schedulers;
13 |
14 | /**
15 | * Created by Mr.Yangxiufeng
16 | * DATE 2016/8/9
17 | * owspace
18 | */
19 | public class DetailPresenter implements DetailContract.Presenter {
20 | private DetailContract.View view;
21 | private ApiService apiService;
22 |
23 | @Inject
24 | public DetailPresenter(DetailContract.View view, ApiService apiService) {
25 | this.view = view;
26 | this.apiService = apiService;
27 | }
28 |
29 | @Override
30 | public void getDetail(String itemId) {
31 | apiService.getDetail("api", "getPost", itemId, 1)
32 | .subscribeOn(Schedulers.io())
33 | .observeOn(AndroidSchedulers.mainThread())
34 | .subscribe(new Subscriber>() {
35 | @Override
36 | public void onCompleted() {
37 |
38 | }
39 |
40 | @Override
41 | public void onError(Throwable e) {
42 | view.showOnFailure();
43 | }
44 |
45 | @Override
46 | public void onNext(Result.Data detailEntityData) {
47 | view.updateListUI(detailEntityData.getDatas());
48 | }
49 | });
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/presenter/MainContract.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.presenter;
2 |
3 | import com.github.baby.owspace.model.entity.Item;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by Mr.Yangxiufeng
9 | * DATE 2016/8/2
10 | * owspace
11 | */
12 | public interface MainContract {
13 | interface Presenter{
14 | void getListByPage(int page, int model, String pageId,String deviceId,String createTime);
15 | void getRecommend(String deviceId);
16 | }
17 | interface View{
18 | void showLoading();
19 | void dismissLoading();
20 | void showNoData();
21 | void showNoMore();
22 | void updateListUI(List- itemList);
23 | void showOnFailure();
24 | void showLunar(String content);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/presenter/MainPresenter.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.presenter;
2 |
3 | import com.github.baby.owspace.model.api.ApiService;
4 | import com.github.baby.owspace.model.entity.Item;
5 | import com.github.baby.owspace.model.entity.Result;
6 | import com.github.baby.owspace.util.TimeUtil;
7 | import com.google.gson.JsonElement;
8 | import com.google.gson.JsonObject;
9 | import com.google.gson.JsonParser;
10 | import com.orhanobut.logger.Logger;
11 |
12 | import java.util.List;
13 |
14 | import javax.inject.Inject;
15 |
16 | import rx.Subscriber;
17 | import rx.android.schedulers.AndroidSchedulers;
18 | import rx.schedulers.Schedulers;
19 |
20 | /**
21 | * Created by Mr.Yangxiufeng
22 | * DATE 2016/8/2
23 | * owspace
24 | */
25 | public class MainPresenter implements MainContract.Presenter {
26 | private MainContract.View view;
27 | private ApiService apiService;
28 |
29 | @Inject
30 | public MainPresenter(MainContract.View view,ApiService apiService) {
31 | this.view = view;
32 | this.apiService = apiService;
33 | Logger.d("apppp:"+apiService);
34 | }
35 |
36 | @Override
37 | public void getListByPage(int page, int model, String pageId, String deviceId, String createTime) {
38 | apiService.getList("api", "getList", page, model, pageId, createTime, "android", "1.3.0", TimeUtil.getCurrentSeconds(), deviceId, 1)
39 | .subscribeOn(Schedulers.io())
40 | .observeOn(AndroidSchedulers.mainThread())
41 | .subscribe(new Subscriber>>() {
42 | @Override
43 | public void onCompleted() {
44 |
45 | }
46 |
47 | @Override
48 | public void onError(Throwable e) {
49 | e.printStackTrace();
50 | view.showOnFailure();
51 | }
52 |
53 | @Override
54 | public void onNext(Result.Data
> listData) {
55 | int size = listData.getDatas().size();
56 | if (size > 0) {
57 | view.updateListUI(listData.getDatas());
58 | } else {
59 | view.showNoMore();
60 | }
61 | }
62 | });
63 | }
64 |
65 | @Override
66 | public void getRecommend(String deviceId) {
67 | String key = TimeUtil.getDate("yyyyMMdd");
68 | Logger.e("getRecommend key:"+key);
69 | apiService.getRecommend("home","Api","getLunar","android",deviceId,deviceId)
70 | .subscribeOn(Schedulers.io())
71 | .observeOn(AndroidSchedulers.mainThread())
72 | .subscribe(new Subscriber() {
73 | @Override
74 | public void onCompleted() {
75 |
76 | }
77 |
78 | @Override
79 | public void onError(Throwable e) {
80 | Logger.e("onError:");
81 | e.printStackTrace();
82 | }
83 |
84 | @Override
85 | public void onNext(String s) {
86 | String key = TimeUtil.getDate("yyyyMMdd");
87 | try {
88 | JsonParser jsonParser = new JsonParser();
89 | JsonElement jel = jsonParser.parse(s);
90 | JsonObject jsonObject = jel.getAsJsonObject();
91 | jsonObject = jsonObject.getAsJsonObject("datas");
92 | jsonObject = jsonObject.getAsJsonObject(key);
93 | view.showLunar(jsonObject.get("thumbnail").getAsString());
94 | }catch (Exception e){
95 | e.printStackTrace();
96 | }
97 | }
98 | });
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/presenter/SplashContract.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.presenter;
2 |
3 |
4 | /**
5 | * Created by Mr.Yangxiufeng
6 | * DATE 2016/7/22
7 | * owspace
8 | */
9 | public interface SplashContract {
10 | interface Presenter {
11 | void getSplash(String deviceId);
12 | }
13 | interface View {
14 |
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/presenter/SplashPresenter.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.presenter;
2 |
3 |
4 | import com.github.baby.owspace.app.OwspaceApplication;
5 | import com.github.baby.owspace.model.api.ApiService;
6 | import com.github.baby.owspace.model.entity.SplashEntity;
7 | import com.github.baby.owspace.util.NetUtil;
8 | import com.github.baby.owspace.util.OkHttpImageDownloader;
9 | import com.github.baby.owspace.util.TimeUtil;
10 | import com.orhanobut.logger.Logger;
11 |
12 | import java.util.List;
13 |
14 | import javax.inject.Inject;
15 |
16 | import rx.Subscriber;
17 | import rx.schedulers.Schedulers;
18 |
19 | /**
20 | * Created by Mr.Yangxiufeng
21 | * DATE 2016/7/22
22 | * owspace
23 | */
24 | public class SplashPresenter implements SplashContract.Presenter{
25 | private SplashContract.View view;
26 | private ApiService apiService;
27 | @Inject
28 | public SplashPresenter(SplashContract.View view, ApiService apiService) {
29 | this.view = view;
30 | this.apiService = apiService;
31 | Logger.d("apppp:"+apiService);
32 | }
33 | @Override
34 | public void getSplash(String deviceId ) {
35 | String client = "android";
36 | String version = "1.3.0";
37 | Long time = TimeUtil.getCurrentSeconds();
38 | apiService.getSplash(client,version,time,deviceId)
39 | .subscribeOn(Schedulers.io())
40 | .observeOn(Schedulers.io())
41 | .subscribe(new Subscriber() {
42 | @Override
43 | public void onCompleted() {
44 | Logger.e("load splash onCompleted");
45 | }
46 |
47 | @Override
48 | public void onError(Throwable e) {
49 | Logger.e(e,"load splash failed:");
50 | }
51 | @Override
52 | public void onNext(SplashEntity splashEntity) {
53 | if (NetUtil.isWifi(OwspaceApplication.getInstance().getApplicationContext())){
54 | if (splashEntity != null){
55 | List imgs = splashEntity.getImages();
56 | for (String url:imgs) {
57 | OkHttpImageDownloader.download(url);
58 | }
59 | }
60 | }else{
61 | Logger.i("不是WIFI环境,就不去下载图片了");
62 | }
63 | }
64 | });
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/util/AppUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.util;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.content.pm.PackageManager;
6 | import android.telephony.TelephonyManager;
7 | import android.view.WindowManager;
8 |
9 | /**
10 | * Created by Mr.Yangxiufeng
11 | * DATE 2016/7/21
12 | * owspace
13 | */
14 | public class AppUtil {
15 | /**
16 | * 获取app版本名
17 | */
18 | public static String getAppVersionName(Context context){
19 | PackageManager pm = context.getPackageManager();
20 | PackageInfo pi;
21 | try {
22 | pi = pm.getPackageInfo(context.getPackageName(),0);
23 | return pi.versionName;
24 | } catch (PackageManager.NameNotFoundException e) {
25 | e.printStackTrace();
26 | }
27 | return "";
28 | }
29 |
30 | /**
31 | * 获取应用程序版本名称信息
32 | */
33 | public static String getVersionName(Context context)
34 | {
35 | try{
36 | PackageManager packageManager = context.getPackageManager();
37 | PackageInfo packageInfo = packageManager.getPackageInfo(
38 | context.getPackageName(), 0);
39 | return packageInfo.versionName;
40 | }catch (PackageManager.NameNotFoundException e) {
41 | e.printStackTrace();
42 | }
43 | return null;
44 | }
45 |
46 | /**
47 | * 获取app版本号
48 | */
49 | public static int getAppVersionCode(Context context){
50 | PackageManager pm = context.getPackageManager();
51 | PackageInfo pi;
52 | try {
53 | pi = pm.getPackageInfo(context.getPackageName(),0);
54 | return pi.versionCode;
55 | } catch (PackageManager.NameNotFoundException e) {
56 | e.printStackTrace();
57 | }
58 | return 0;
59 | }
60 | public static String getDeviceId(Context context){
61 | TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
62 | return tm.getDeviceId();
63 | }
64 | public static int dp2px(Context paramContext, float paramFloat)
65 | {
66 | float scale = paramContext.getResources().getDisplayMetrics().density;
67 | return (int)(0.5F + paramFloat * scale);
68 | }
69 | public static int getWindowWidth(Context paramContext)
70 | {
71 | return getWindowManager(paramContext).getDefaultDisplay().getWidth();
72 | }
73 | public static WindowManager getWindowManager(Context paramContext)
74 | {
75 | return (WindowManager)paramContext.getSystemService(Context.WINDOW_SERVICE);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/util/FileUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.util;
2 |
3 | import android.os.Environment;
4 |
5 | import com.orhanobut.logger.Logger;
6 |
7 | import java.io.File;
8 | import java.io.IOException;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 |
13 | /**
14 | * Created by Mr.Yangxiufeng
15 | * DATE 2016/7/25
16 | * owspace
17 | */
18 | public class FileUtil {
19 | public static final String SDPATH = Environment.getExternalStorageDirectory().getAbsolutePath();
20 |
21 | public static final String ADPATH = FileUtil.SDPATH + "/Owspace";
22 |
23 | public static void createSdDir() {
24 | File file = new File(FileUtil.ADPATH);
25 | if (!file.exists()) {
26 | boolean create = file.mkdirs();
27 | Logger.d("create = " + create);
28 | } else {
29 | if (!file.isDirectory()) {
30 | file.delete();
31 | file.mkdir();
32 | }
33 | }
34 | }
35 | public static boolean isFileExist(String paramString) {
36 | if (paramString == null)
37 | return false;
38 | File localFile = new File(ADPATH + "/" + paramString);
39 | if (localFile.exists()) {
40 | return true;
41 | }
42 | return false;
43 | }
44 | public static File createFile(String fileName) throws IOException{
45 | File file = new File(ADPATH,fileName);
46 | file.createNewFile();
47 | return file;
48 | }
49 | public static List getAllAD(){
50 | File file = new File(FileUtil.ADPATH);
51 | File[] fileList = file.listFiles();
52 | List list = new ArrayList<>();
53 | if(null != fileList){
54 | for (File f:fileList) {
55 | list.add(f.getAbsolutePath());
56 | }
57 | }
58 | return list;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/util/NetUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.util;
2 |
3 | import android.app.Activity;
4 | import android.content.ComponentName;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.net.ConnectivityManager;
8 | import android.net.NetworkInfo;
9 |
10 | /**
11 | * Created by Mr.Yangxiufeng
12 | * DATE 2016/7/21
13 | * owspace
14 | */
15 | public class NetUtil {
16 | /**
17 | * 判断网络是否连接
18 | *
19 | * @param context
20 | * @return
21 | */
22 | public static boolean isConnected(Context context)
23 | {
24 |
25 | ConnectivityManager connectivity = (ConnectivityManager) context
26 | .getSystemService(Context.CONNECTIVITY_SERVICE);
27 |
28 | if (null != connectivity)
29 | {
30 |
31 | NetworkInfo info = connectivity.getActiveNetworkInfo();
32 | if (null != info && info.isConnected())
33 | {
34 | if (info.getState() == NetworkInfo.State.CONNECTED)
35 | {
36 | return true;
37 | }
38 | }
39 | }
40 | return false;
41 | }
42 |
43 | /**
44 | * 判断是否是wifi连接
45 | */
46 | public static boolean isWifi(Context context)
47 | {
48 | ConnectivityManager cm = (ConnectivityManager) context
49 | .getSystemService(Context.CONNECTIVITY_SERVICE);
50 |
51 | if (cm == null)
52 | return false;
53 | return cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;
54 |
55 | }
56 |
57 | /**
58 | * 打开网络设置界面
59 | */
60 | public static void openSetting(Activity activity)
61 | {
62 | Intent intent = new Intent("/");
63 | ComponentName cm = new ComponentName("com.android.settings",
64 | "com.android.settings.WirelessSettings");
65 | intent.setComponent(cm);
66 | intent.setAction("android.intent.action.VIEW");
67 | activity.startActivityForResult(intent, 0);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/util/OkHttpImageDownloader.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.util;
2 |
3 | import com.github.baby.owspace.model.util.HttpUtils;
4 | import com.orhanobut.logger.Logger;
5 |
6 | import java.io.FileOutputStream;
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 |
10 | import okhttp3.Request;
11 |
12 | /**
13 | * Created by Mr.Yangxiufeng
14 | * DATE 2016/7/25
15 | * owspace
16 | */
17 | public class OkHttpImageDownloader {
18 | public static void download(String url){
19 | final Request request = new Request.Builder().url(url).build();
20 | HttpUtils.client.newCall(request).enqueue(new okhttp3.Callback() {
21 | @Override
22 | public void onFailure(okhttp3.Call call, IOException e) {
23 | Logger.d(e);
24 | }
25 |
26 | @Override
27 | public void onResponse(okhttp3.Call call, okhttp3.Response response) throws IOException {
28 |
29 | FileUtil.createSdDir();
30 | String url = response.request().url().toString();
31 | int index = url.lastIndexOf("/");
32 | String pictureName = url.substring(index+1);
33 | if(FileUtil.isFileExist(pictureName)){
34 | return;
35 | }
36 | Logger.i("pictureName="+pictureName);
37 | FileOutputStream fos = new FileOutputStream(FileUtil.createFile(pictureName));
38 | InputStream in = response.body().byteStream();
39 | byte[] buf = new byte[1024];
40 | int len = 0;
41 | while ((len = in.read(buf))!=-1){
42 | fos.write(buf,0,len);
43 | }
44 | fos.flush();
45 | in.close();
46 | fos.close();
47 | }
48 | });
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/util/PreferenceUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.util;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.preference.PreferenceManager;
6 |
7 | /**
8 | * Created by Mr.Yangxiufeng
9 | * DATE 2016/8/2
10 | * owspace
11 | */
12 | public class PreferenceUtils {
13 | public static String getPrefString(Context context, String key,
14 | final String defaultValue) {
15 | final SharedPreferences settings = PreferenceManager
16 | .getDefaultSharedPreferences(context);
17 | return settings.getString(key, defaultValue);
18 | }
19 |
20 | public static void setPrefString(Context context, final String key,
21 | final String value) {
22 | final SharedPreferences settings = PreferenceManager
23 | .getDefaultSharedPreferences(context);
24 | settings.edit().putString(key, value).apply();
25 | }
26 |
27 | public static boolean getPrefBoolean(Context context, final String key,
28 | final boolean defaultValue) {
29 | final SharedPreferences settings = PreferenceManager
30 | .getDefaultSharedPreferences(context);
31 | return settings.getBoolean(key, defaultValue);
32 | }
33 |
34 | public static boolean hasKey(Context context, final String key) {
35 | return PreferenceManager.getDefaultSharedPreferences(context).contains(
36 | key);
37 | }
38 |
39 | public static void setPrefBoolean(Context context, final String key,
40 | final boolean value) {
41 | final SharedPreferences settings = PreferenceManager
42 | .getDefaultSharedPreferences(context);
43 | settings.edit().putBoolean(key, value).apply();
44 | }
45 |
46 | public static void setPrefInt(Context context, final String key,
47 | final int value) {
48 | final SharedPreferences settings = PreferenceManager
49 | .getDefaultSharedPreferences(context);
50 | settings.edit().putInt(key, value).apply();
51 | }
52 |
53 | public static int getPrefInt(Context context, final String key,
54 | final int defaultValue) {
55 | final SharedPreferences settings = PreferenceManager
56 | .getDefaultSharedPreferences(context);
57 | return settings.getInt(key, defaultValue);
58 | }
59 |
60 | public static void setPrefFloat(Context context, final String key,
61 | final float value) {
62 | final SharedPreferences settings = PreferenceManager
63 | .getDefaultSharedPreferences(context);
64 | settings.edit().putFloat(key, value).apply();
65 | }
66 |
67 | public static float getPrefFloat(Context context, final String key,
68 | final float defaultValue) {
69 | final SharedPreferences settings = PreferenceManager
70 | .getDefaultSharedPreferences(context);
71 | return settings.getFloat(key, defaultValue);
72 | }
73 |
74 | public static void setSettingLong(Context context, final String key,
75 | final long value) {
76 | final SharedPreferences settings = PreferenceManager
77 | .getDefaultSharedPreferences(context);
78 | settings.edit().putLong(key, value).apply();
79 | }
80 |
81 | public static long getPrefLong(Context context, final String key,
82 | final long defaultValue) {
83 | final SharedPreferences settings = PreferenceManager
84 | .getDefaultSharedPreferences(context);
85 | return settings.getLong(key, defaultValue);
86 | }
87 |
88 | public static void clearPreference(Context context,
89 | final SharedPreferences p) {
90 | final SharedPreferences.Editor editor = p.edit();
91 | editor.clear();
92 | editor.apply();
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/util/TimeUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.util;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Calendar;
5 | import java.util.Date;
6 | import java.util.Locale;
7 |
8 | /**
9 | * Created by Mr.Yangxiufeng
10 | * DATE 2016/7/21
11 | * owspace
12 | */
13 | public class TimeUtil {
14 | public static long getCurrentSeconds(){
15 | long ls = System.currentTimeMillis()/1000;
16 | return ls;
17 | }
18 | public static String[] getCalendarShowTime(long paramLong)
19 | {
20 | String[] localObject;
21 | String str = new SimpleDateFormat("yyyy:MMM:d", Locale.ENGLISH).format(new Date(paramLong));
22 | try
23 | {
24 | String[] arrayOfString = str.split(":");
25 | localObject = arrayOfString;
26 | if ((localObject != null) && (localObject.length == 3));
27 | return localObject;
28 | }
29 | catch (Exception localException)
30 | {
31 | while (true)
32 | localException.printStackTrace();
33 | }
34 | }
35 |
36 | public static String[] getCalendarShowTime(String paramString)
37 | {
38 | try {
39 | long l = Long.valueOf(paramString);
40 | Calendar localCalendar = Calendar.getInstance();
41 | localCalendar.setTimeInMillis(1000L * l);
42 | return getCalendarShowTime(localCalendar.getTimeInMillis());
43 | } catch (NumberFormatException e) {
44 | e.printStackTrace();
45 | }
46 | return null;
47 | }
48 | public static String getDate(String formate){
49 | String str = new SimpleDateFormat(formate, Locale.ENGLISH).format(new Date());
50 | return str;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/util/TimeUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.util;
2 |
3 | import android.annotation.SuppressLint;
4 |
5 | /**
6 | * Created by Mr.Yangxiufeng
7 | * DATE 2016/11/24
8 | * owspace
9 | */
10 |
11 | public class TimeUtils {
12 | /**
13 | * Parse the time in milliseconds into String with the format: hh:mm:ss or mm:ss
14 | *
15 | * @param duration The time needs to be parsed.
16 | */
17 | @SuppressLint("DefaultLocale")
18 | public static String formatDuration(int duration) {
19 | duration /= 1000; // milliseconds into seconds
20 | int minute = duration / 60;
21 | int hour = minute / 60;
22 | minute %= 60;
23 | int second = duration % 60;
24 | if (hour != 0)
25 | return String.format("%2d:%02d:%02d", hour, minute, second);
26 | else
27 | return String.format("%02d:%02d", minute, second);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/baby/owspace/util/tool/RxBus.java:
--------------------------------------------------------------------------------
1 | package com.github.baby.owspace.util.tool;
2 |
3 | import rx.Observable;
4 | import rx.subjects.PublishSubject;
5 | import rx.subjects.SerializedSubject;
6 | import rx.subjects.Subject;
7 |
8 | /**
9 | * Created by Mr.Yangxiufeng
10 | * DATE 2016/8/22
11 | * owspace
12 | */
13 | public class RxBus {
14 | private static volatile RxBus instance;
15 |
16 | private final Subject