Browse Source

1:创建知乎日报组件。

guiying712 8 years ago
parent
commit
c1f07ef57f
26 changed files with 735 additions and 127 deletions
  1. 1 1
      build.gradle
  2. 14 0
      common/src/main/java/com/guiying/common/base/BaseActionBarActivity.java
  3. 13 0
      common/src/main/java/com/guiying/common/base/BaseActivity.java
  4. 1 1
      common/src/main/java/com/guiying/common/http/HttpClient.java
  5. 16 0
      common/src/main/java/com/guiying/common/http/InfoCallback.java
  6. 1 1
      gradle.properties
  7. 2 1
      news/src/main/debug/AndroidManifest.xml
  8. 0 1
      news/src/main/java/com/guiying/news/News.java
  9. 26 0
      news/src/main/java/com/guiying/news/data/NewsDataSource.java
  10. 87 0
      news/src/main/java/com/guiying/news/data/bean/MessageDetail.java
  11. 77 0
      news/src/main/java/com/guiying/news/data/bean/Story.java
  12. 32 0
      news/src/main/java/com/guiying/news/data/bean/StoryList.java
  13. 46 0
      news/src/main/java/com/guiying/news/data/source/RemoteNewsDataSource.java
  14. 0 78
      news/src/main/java/com/guiying/news/main/NewsActivity.java
  15. 70 0
      news/src/main/java/com/guiying/news/main/NewsCenterActivity.java
  16. 58 0
      news/src/main/java/com/guiying/news/main/NewsListAdapter.java
  17. 13 1
      news/src/main/java/com/guiying/news/main/NewsListContract.java
  18. 47 0
      news/src/main/java/com/guiying/news/main/NewsListPresenter.java
  19. 93 0
      news/src/main/java/com/guiying/news/main/NewsListView.java
  20. 71 0
      news/src/main/java/com/guiying/news/main/NewsListViewAdapter.java
  21. 0 11
      news/src/main/java/com/guiying/news/main/NewsPresenter.java
  22. 0 13
      news/src/main/java/com/guiying/news/main/NewsView.java
  23. 8 4
      news/src/main/java/debug/NewsApplication.java
  24. 2 1
      news/src/main/release/AndroidManifest.xml
  25. 29 14
      news/src/main/res/layout/activity_news.xml
  26. 28 0
      news/src/main/res/layout/item_news_list.xml

+ 1 - 1
build.gradle

@@ -53,6 +53,6 @@ ext {
     //不成熟开源库,需经常检查升级版本
     aptCompilerVersion = "1.1.7"
     routerVersion = "1.2.2"
-    easyRecyclerVersion = "4.3.8"
+    easyRecyclerVersion = "4.4.0"
     cookieVersion = "v1.0.1"
 }

+ 14 - 0
common/src/main/java/com/guiying/common/base/BaseActionBarActivity.java

@@ -38,6 +38,20 @@ public abstract class BaseActionBarActivity extends BaseActivity {
         }
     }
 
+
+    /**
+     * 更新标题
+     *
+     * @param title 标题
+     */
+    protected void setTitle(String title) {
+        ActionBar actionBar = getSupportActionBar();
+        if (actionBar != null) {
+            actionBar.setTitle(title);
+        }
+    }
+
+
     @Override
     public boolean onSupportNavigateUp() {
         onBackPressed();

+ 13 - 0
common/src/main/java/com/guiying/common/base/BaseActivity.java

@@ -3,7 +3,9 @@ package com.guiying.common.base;
 import android.content.Intent;
 import android.os.Bundle;
 import android.support.annotation.IdRes;
+import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
 import android.view.View;
 
 /**
@@ -39,6 +41,17 @@ public abstract class BaseActivity extends AppCompatActivity {
         }
     }
 
+    protected void setToolbar(Toolbar toolbar, String title) {
+        setSupportActionBar(toolbar);
+        ActionBar actionBar = getSupportActionBar();
+        if (null != actionBar) {
+            actionBar.setDisplayHomeAsUpEnabled(true);
+            actionBar.setDisplayShowHomeEnabled(true);
+            //actionBar.setDisplayShowTitleEnabled(false);//隐藏Title
+            actionBar.setTitle(title);
+        }
+    }
+
     @Override
     protected void onDestroy() {
         super.onDestroy();

+ 1 - 1
common/src/main/java/com/guiying/common/http/HttpClient.java

@@ -318,7 +318,7 @@ public class HttpClient {
                 onResultListener.onSuccess(DataParseUtil.parseObject(data, clazz));
                 break;
             case ARRAY:
-                onResultListener.onSuccess(DataParseUtil.parseToArrayList(data, clazz));
+                onResultListener.onSuccess(DataParseUtil.parseToList(data, clazz));
                 break;
             case XML:
                 onResultListener.onSuccess(DataParseUtil.parseXml(data, clazz));

+ 16 - 0
common/src/main/java/com/guiying/common/http/InfoCallback.java

@@ -0,0 +1,16 @@
+package com.guiying.common.http;
+
+/**
+ * <p>数据回调接口</p>
+ *
+ * @author 张华洋 2017/3/22 13:36
+ * @version V1.2.0
+ * @name InfoCallback
+ */
+public interface InfoCallback<T> {
+
+    void onSuccess(T info);
+
+    void onError(int code, String message);
+
+}

+ 1 - 1
gradle.properties

@@ -22,4 +22,4 @@ localBuildToolsVersion=25.0.2
 localGradlePluginVersion=2.3.0
 
 # 每次更改“isModule”的值后,需要点击 "Sync Project" 按钮
-isModule=false
+isModule=true

+ 2 - 1
news/src/main/debug/AndroidManifest.xml

@@ -10,7 +10,8 @@
         android:supportsRtl="true"
         android:theme="@style/AppTheme">
         <activity
-            android:name=".main.NewsActivity"
+            android:name=".main.NewsCenterActivity"
+            android:theme="@style/AppTheme.NoActionBar"
             android:screenOrientation="portrait">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />

+ 0 - 1
news/src/main/java/com/guiying/news/News.java

@@ -9,7 +9,6 @@ import com.github.mzule.activityrouter.annotation.Module;
  * @version V1.2.0
  * @name news
  */
-
 @Module("news")
 public class News {
 }

+ 26 - 0
news/src/main/java/com/guiying/news/data/NewsDataSource.java

@@ -0,0 +1,26 @@
+package com.guiying.news.data;
+
+import com.guiying.common.http.InfoCallback;
+import com.guiying.news.data.bean.StoryList;
+
+/**
+ * <p>类说明</p>
+ *
+ * @author 张华洋 2017/4/20 22:02
+ * @version V1.2.0
+ * @name NewsDataSource
+ */
+public interface NewsDataSource {
+
+
+    /**
+     * 获取
+     *
+     * @param date
+     * @param callback 回调
+     */
+    void getNewsList(String date, InfoCallback<StoryList> callback);
+
+
+}
+

+ 87 - 0
news/src/main/java/com/guiying/news/data/bean/MessageDetail.java

@@ -0,0 +1,87 @@
+package com.guiying.news.data.bean;
+
+import java.util.List;
+
+public class MessageDetail {
+    private String body;
+    private String image_source;
+    private String title;
+    private String image;
+    private String share_url;
+    private List<String> recommenders;
+    private String ga_prefix;
+    private String type;
+    private String id;
+
+    public String getBody() {
+        return body;
+    }
+
+    public void setBody(String body) {
+        this.body = body;
+    }
+
+    public String getImage_source() {
+        return image_source;
+    }
+
+    public void setImage_source(String image_source) {
+        this.image_source = image_source;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getImage() {
+        return image;
+    }
+
+    public void setImage(String image) {
+        this.image = image;
+    }
+
+    public String getShare_url() {
+        return share_url;
+    }
+
+    public void setShare_url(String share_url) {
+        this.share_url = share_url;
+    }
+
+    public List<String> getRecommenders() {
+        return recommenders;
+    }
+
+    public void setRecommenders(List<String> recommenders) {
+        this.recommenders = recommenders;
+    }
+
+    public String getGa_prefix() {
+        return ga_prefix;
+    }
+
+    public void setGa_prefix(String ga_prefix) {
+        this.ga_prefix = ga_prefix;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+}

+ 77 - 0
news/src/main/java/com/guiying/news/data/bean/Story.java

@@ -0,0 +1,77 @@
+package com.guiying.news.data.bean;
+
+/**
+ * 日报新闻实体类
+ */
+public class Story {
+
+    /**
+     * 新闻标题
+     **/
+    private String title;
+    /**
+     * 供 Google Analytics 使用
+     **/
+    private String ga_prefix;
+    /**
+     * 图像地址(官方 API 使用数组形式。目前暂未有使用多张图片的情形出现,曾见无 images 属性的情况,请在使用中注意 )
+     **/
+    private String[] images;
+    /**
+     * 消息是否包含多张图片(仅出现在包含多图的新闻中)
+     **/
+    private String multipic;
+    private String type;
+    /**
+     * url 与 share_url 中最后的数字(应为内容的 id)
+     **/
+    private String id;
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getGa_prefix() {
+        return ga_prefix;
+    }
+
+    public void setGa_prefix(String ga_prefix) {
+        this.ga_prefix = ga_prefix;
+    }
+
+    public String[] getImages() {
+        return images;
+    }
+
+    public void setImages(String[] images) {
+        this.images = images;
+    }
+
+    public String getMultipic() {
+        return multipic;
+    }
+
+    public void setMultipic(String multipic) {
+        this.multipic = multipic;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+}

+ 32 - 0
news/src/main/java/com/guiying/news/data/bean/StoryList.java

@@ -0,0 +1,32 @@
+package com.guiying.news.data.bean;
+
+import java.util.List;
+
+/**
+ * <p>类说明</p>
+ *
+ * @author 张华洋 2017/4/20 23:04
+ * @version V1.2.0
+ * @name StoryList
+ */
+public class StoryList {
+
+    private String date;
+    private List<Story> stories;
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public List<Story> getStories() {
+        return stories;
+    }
+
+    public void setStories(List<Story> stories) {
+        this.stories = stories;
+    }
+}

+ 46 - 0
news/src/main/java/com/guiying/news/data/source/RemoteNewsDataSource.java

@@ -0,0 +1,46 @@
+package com.guiying.news.data.source;
+
+import com.guiying.common.http.HttpClient;
+import com.guiying.common.http.InfoCallback;
+import com.guiying.common.http.OnResultListener;
+import com.guiying.news.Constants;
+import com.guiying.news.data.NewsDataSource;
+import com.guiying.news.data.bean.StoryList;
+
+import static com.guiying.common.http.HttpClient.OBJECT;
+
+/**
+ * <p>类说明</p>
+ *
+ * @author 张华洋 2017/4/20 23:32
+ * @version V1.2.0
+ * @name RemoteNewsDataSource
+ */
+public class RemoteNewsDataSource implements NewsDataSource {
+
+    @Override
+    public void getNewsList(String date, final InfoCallback<StoryList> callback) {
+        HttpClient client = new HttpClient.Builder()
+                .baseUrl(Constants.ZHIHU_DAILY_BEFORE_MESSAGE)
+                .url(date)
+                .bodyType(OBJECT, StoryList.class)
+                .build();
+        client.get(new OnResultListener<StoryList>() {
+
+            @Override
+            public void onSuccess(StoryList result) {
+                callback.onSuccess(result);
+            }
+
+            @Override
+            public void onError(int code, String message) {
+                callback.onError(code, message);
+            }
+
+            @Override
+            public void onFailure(String message) {
+                callback.onError(0, message);
+            }
+        });
+    }
+}

+ 0 - 78
news/src/main/java/com/guiying/news/main/NewsActivity.java

@@ -1,78 +0,0 @@
-package com.guiying.news.main;
-
-import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
-import android.widget.Toast;
-
-import com.github.mzule.activityrouter.annotation.Router;
-import com.guiying.common.base.BaseActionBarActivity;
-import com.guiying.common.http.HttpClient;
-import com.guiying.common.http.OnResultListener;
-import com.guiying.common.utils.ToastUtils;
-import com.guiying.news.Constants;
-import com.guiying.news.R;
-import com.orhanobut.logger.Logger;
-
-import es.dmoral.toasty.Toasty;
-
-@Router("news")
-public class NewsActivity extends BaseActionBarActivity implements View.OnClickListener {
-
-    protected Button mButton;
-
-    @Override
-    protected int setTitleId() {
-        return R.string.news_activity_title;
-    }
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        super.setContentView(R.layout.activity_news);
-        login();
-        initView();
-    }
-
-
-    /**
-     * 在这里模拟登陆,然后拿到sessionId或者Token
-     * 这样就能够在组件请求接口了
-     */
-    private void login() {
-        HttpClient client = new HttpClient.Builder()
-                .baseUrl(Constants.ZHIHU_DAILY_BEFORE_MESSAGE)
-                .url("20170225")
-                .build();
-        client.get(new OnResultListener<String>() {
-
-            @Override
-            public void onSuccess(String result) {
-                Toasty.info(NewsActivity.this, "Here is some info for you.", Toast.LENGTH_SHORT, true).show();
-            }
-
-            @Override
-            public void onError(int code, String message) {
-                Logger.e(message);
-            }
-
-            @Override
-            public void onFailure(String message) {
-                Logger.e(message);
-            }
-        });
-    }
-
-
-    @Override
-    public void onClick(View view) {
-        if (view.getId() == R.id.button1) {
-            ToastUtils.showShortToast("kannidmfdsfsf ");
-        }
-    }
-
-    private void initView() {
-        mButton = (Button) findViewById(R.id.button1);
-        mButton.setOnClickListener(NewsActivity.this);
-    }
-}

+ 70 - 0
news/src/main/java/com/guiying/news/main/NewsCenterActivity.java

@@ -0,0 +1,70 @@
+package com.guiying.news.main;
+
+import android.os.Bundle;
+import android.support.design.widget.TabLayout;
+import android.support.v4.view.ViewPager;
+import android.support.v7.widget.Toolbar;
+
+import com.github.mzule.activityrouter.annotation.Router;
+import com.guiying.common.base.BaseActivity;
+import com.guiying.news.R;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Locale;
+
+@Router("news")
+public class NewsCenterActivity extends BaseActivity {
+
+    protected Toolbar mToolBar;
+    protected TabLayout mTabLayout;
+    protected ViewPager mViewPager;
+    private NewsListViewAdapter mListAdapter;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        super.setContentView(R.layout.activity_news);
+        mToolBar = (Toolbar) findViewById(R.id.news_title_bar);
+        setToolbar(mToolBar, "知乎日报");
+        mTabLayout = (TabLayout) findViewById(R.id.date_tab);
+        mViewPager = (ViewPager) findViewById(R.id.message_pager);
+        mListAdapter = new NewsListViewAdapter(getMessageListViews(), getWeekDate());
+        mViewPager.setAdapter(mListAdapter);
+        //setupWithViewPager必须在ViewPager.setAdapter()之后调用
+        mTabLayout.setupWithViewPager(mViewPager);
+    }
+
+    /**
+     * 获取ViewPager的viewList
+     */
+    private List<NewsListView> getMessageListViews() {
+        List<NewsListView> viewList = new ArrayList<>();
+        List<String> weekDate = getWeekDate();
+        if (weekDate != null) {
+            for (String tab : weekDate) {
+                viewList.add(new NewsListView(this, tab));
+            }
+        }
+        return viewList;
+    }
+
+
+    /**
+     * 获取过去7天的时期,格式为yymmdd
+     **/
+    public static List<String> getWeekDate() {
+        List<String> dates = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
+        for (int i = 0; i < 7; i++) {
+            Calendar calendar = Calendar.getInstance();
+            calendar.add(Calendar.DAY_OF_YEAR, 1 - i);
+            dates.add(simpleDateFormat.format(calendar.getTime()));
+        }
+        return dates;
+    }
+
+
+}

+ 58 - 0
news/src/main/java/com/guiying/news/main/NewsListAdapter.java

@@ -0,0 +1,58 @@
+package com.guiying.news.main;
+
+import android.content.Context;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.engine.DiskCacheStrategy;
+import com.guiying.news.R;
+import com.guiying.news.data.bean.Story;
+import com.jude.easyrecyclerview.adapter.BaseViewHolder;
+import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
+
+/**
+ * <p>类说明</p>
+ *
+ * @author 张华洋 2017/4/20 22:26
+ * @version V1.2.0
+ * @name NewsListAdapter
+ */
+
+
+public class NewsListAdapter extends RecyclerArrayAdapter<Story> {
+
+    public NewsListAdapter(Context context) {
+        super(context);
+    }
+
+    @Override
+    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
+        return new NewsListHolder(parent);
+    }
+
+    private class NewsListHolder extends BaseViewHolder<Story> {
+
+        private TextView mTextView;
+        private ImageView mImageView;
+
+        NewsListHolder(ViewGroup parent) {
+            super(parent, R.layout.item_news_list);
+            mTextView = $(R.id.news_title);
+            mImageView = $(R.id.news_image);
+        }
+
+        @Override
+        public void setData(Story data) {
+            super.setData(data);
+            mTextView.setText(data.getTitle());
+            Glide.with(getContext())
+                    .load(data.getImages()[0])
+                    .centerCrop()
+                    .crossFade()
+                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
+                    .into(mImageView);
+        }
+    }
+}

+ 13 - 1
news/src/main/java/com/guiying/news/main/NewsContract.java → news/src/main/java/com/guiying/news/main/NewsListContract.java

@@ -2,6 +2,7 @@ package com.guiying.news.main;
 
 import com.guiying.common.base.BasePresenter;
 import com.guiying.common.base.BaseView;
+import com.guiying.news.data.bean.StoryList;
 
 /**
  * <p>类说明</p>
@@ -10,14 +11,25 @@ import com.guiying.common.base.BaseView;
  * @version V1.2.0
  * @name NewsContract
  */
-public interface NewsContract {
+public interface NewsListContract {
 
     interface View extends BaseView<Presenter> {
 
+        boolean isActive();
+
+        void showNewsList(StoryList info);
+
     }
 
     interface Presenter extends BasePresenter {
 
+        /**
+         * 获取最新列表
+         *
+         * @param date
+         */
+        void getNewMessages(int page, int size, String date);
+
     }
 
 }

+ 47 - 0
news/src/main/java/com/guiying/news/main/NewsListPresenter.java

@@ -0,0 +1,47 @@
+package com.guiying.news.main;
+
+import com.guiying.common.http.InfoCallback;
+import com.guiying.news.data.NewsDataSource;
+import com.guiying.news.data.bean.StoryList;
+import com.guiying.news.data.source.RemoteNewsDataSource;
+
+/**
+ * <p>类说明</p>
+ *
+ * @author 张华洋 2017/2/22 20:33
+ * @version V1.2.0
+ * @name GirlsPresenter
+ */
+public class NewsListPresenter implements NewsListContract.Presenter {
+
+    private NewsListContract.View mView;
+    private NewsDataSource mDataSource;
+
+    public NewsListPresenter(NewsListContract.View view) {
+        mView = view;
+        mDataSource = new RemoteNewsDataSource();
+        mView.setPresenter(this);
+    }
+
+    @Override
+    public void start() {
+
+    }
+
+    @Override
+    public void getNewMessages(int page, int size, String date) {
+        mDataSource.getNewsList(date, new InfoCallback<StoryList>() {
+            @Override
+            public void onSuccess(StoryList info) {
+                if (mView.isActive()) {
+                    mView.showNewsList(info);
+                }
+            }
+
+            @Override
+            public void onError(int code, String message) {
+
+            }
+        });
+    }
+}

+ 93 - 0
news/src/main/java/com/guiying/news/main/NewsListView.java

@@ -0,0 +1,93 @@
+package com.guiying.news.main;
+
+import android.content.Context;
+import android.support.v4.widget.SwipeRefreshLayout;
+import android.support.v7.widget.LinearLayoutManager;
+import android.util.AttributeSet;
+
+import com.guiying.news.R;
+import com.guiying.news.data.bean.StoryList;
+import com.jude.easyrecyclerview.EasyRecyclerView;
+import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
+import com.jude.easyrecyclerview.decoration.DividerDecoration;
+
+/**
+ * <p>类说明</p>
+ *
+ * @author 张华洋 2017/4/20 22:21
+ * @version V1.2.0
+ * @name NewListView
+ */
+public class NewsListView extends EasyRecyclerView implements NewsListContract.View, SwipeRefreshLayout.OnRefreshListener {
+    private NewsListContract.Presenter mPresenter;
+    private String mDate;
+    private NewsListAdapter mAdapter;
+    private boolean isActive = false;
+
+    public NewsListView(Context context, String date) {
+        super(context);
+        mDate = date;
+        initView();
+    }
+
+    public NewsListView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        initView();
+    }
+
+    private void initView() {
+        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
+        setLayoutManager(layoutManager);
+        DividerDecoration dividerDecoration = new DividerDecoration(getResources().getColor(R.color.gray_e0), 20, 20, 0);
+        dividerDecoration.setDrawLastItem(true);
+        addItemDecoration(dividerDecoration);
+        mAdapter = new NewsListAdapter(getContext());
+        mAdapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
+            @Override
+            public void onItemClick(int position) {
+
+            }
+        });
+
+        setAdapterWithProgress(mAdapter);
+        setRefreshListener(this);
+        new NewsListPresenter(this);
+        isActive = true;
+    }
+
+    @Override
+    public void onRefresh() {
+        mPresenter.getNewMessages(1, 20, mDate);
+    }
+
+    @Override
+    protected void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        isActive = true;
+        mPresenter.getNewMessages(1, 20, mDate);
+    }
+
+    @Override
+    protected void onDetachedFromWindow() {
+        super.onDetachedFromWindow();
+        isActive = false;
+    }
+
+    @Override
+    public void setPresenter(NewsListContract.Presenter presenter) {
+        mPresenter = presenter;
+    }
+
+    @Override
+    public boolean isActive() {
+        return isActive;
+    }
+
+    @Override
+    public void showNewsList(StoryList info) {
+        if (info != null) {
+            mAdapter.clear();
+            mAdapter.addAll(info.getStories());
+        }
+    }
+}

+ 71 - 0
news/src/main/java/com/guiying/news/main/NewsListViewAdapter.java

@@ -0,0 +1,71 @@
+package com.guiying.news.main;
+
+import android.support.v4.view.PagerAdapter;
+import android.view.View;
+import android.view.ViewGroup;
+
+import java.util.List;
+
+/**
+ * <p>类说明</p>
+ *
+ * @author 张华洋 2017/4/20 23:41
+ * @version V1.2.0
+ * @name NewsListViewAdapter
+ */
+public class NewsListViewAdapter extends PagerAdapter {
+
+    private final List<? extends View> mViewList;
+    private final List<String> mTabList;
+    private View mCurrentView;
+
+    public NewsListViewAdapter(List<? extends View> list, List<String> dates) {
+        mViewList = list;
+        mTabList = dates;
+    }
+
+    @Override
+    public int getCount() {
+        return mViewList == null ? 0 : mViewList.size();
+    }
+
+    @Override
+    public boolean isViewFromObject(View view, Object object) {
+        return view == object;
+    }
+
+    @Override
+    public Object instantiateItem(ViewGroup container, int position) {
+        container.addView((mViewList.get(position)));
+        return mViewList.get(position);
+    }
+
+    @Override
+    public void destroyItem(ViewGroup container, int position, Object object) {
+        container.removeView(mViewList.get(position));
+    }
+
+    @Override
+    public CharSequence getPageTitle(int position) {
+        if (mTabList == null) {
+            return null;
+        }
+        return mTabList.get(position);
+    }
+
+    /**
+     * 获取当前view的方法
+     */
+    View getCurrentView() {
+        return mCurrentView;
+    }
+
+    @Override
+    public void setPrimaryItem(ViewGroup container, int position, Object object) {
+        super.setPrimaryItem(container, position, object);
+        if (mViewList.size() > 0) {
+            mCurrentView = mViewList.get(position);
+        }
+    }
+
+}

+ 0 - 11
news/src/main/java/com/guiying/news/main/NewsPresenter.java

@@ -1,11 +0,0 @@
-package com.guiying.news.main;
-
-/**
- * <p>类说明</p>
- *
- * @author 张华洋 2017/2/22 20:33
- * @version V1.2.0
- * @name GirlsPresenter
- */
-public class NewsPresenter {
-}

+ 0 - 13
news/src/main/java/com/guiying/news/main/NewsView.java

@@ -1,13 +0,0 @@
-package com.guiying.news.main;
-
-/**
- * <p>类说明</p>
- *
- * @author 张华洋 2017/2/22 20:33
- * @version V1.2.0
- * @name GirlsView
- */
-
-
-public class NewsView {
-}

+ 8 - 4
news/src/main/java/debug/NewsApplication.java

@@ -4,8 +4,11 @@ import com.guiying.common.base.BaseApplication;
 import com.guiying.common.http.HttpClient;
 import com.guiying.common.http.OnResultListener;
 import com.guiying.news.Constants;
+import com.guiying.news.data.bean.StoryList;
 import com.orhanobut.logger.Logger;
 
+import static com.guiying.common.http.HttpClient.OBJECT;
+
 /**
  * <p>类说明</p>
  *
@@ -29,13 +32,14 @@ public class NewsApplication extends BaseApplication {
     private void login() {
         HttpClient client = new HttpClient.Builder()
                 .baseUrl(Constants.ZHIHU_DAILY_BEFORE_MESSAGE)
-                .url("20170225")
+                .url("20170419")
+                .bodyType(OBJECT, StoryList.class)
                 .build();
-        client.get(new OnResultListener<String>() {
+        client.get(new OnResultListener<StoryList>() {
 
             @Override
-            public void onSuccess(String result) {
-                Logger.e(result);
+            public void onSuccess(StoryList result) {
+                Logger.e(result.toString());
             }
 
             @Override

+ 2 - 1
news/src/main/release/AndroidManifest.xml

@@ -3,7 +3,8 @@
 
     <application android:theme="@style/AppTheme">
         <activity
-            android:name=".main.NewsActivity"
+            android:name=".main.NewsCenterActivity"
+            android:theme="@style/AppTheme.NoActionBar"
             android:screenOrientation="portrait" />
     </application>
 

+ 29 - 14
news/src/main/res/layout/activity_news.xml

@@ -1,21 +1,36 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/activity_news"
+<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical"
-    tools:context="com.guiying.news.main.NewsActivity">
+    android:background="#ffff">
 
-    <TextView
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="Hello World!" />
+    <android.support.design.widget.AppBarLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <android.support.v7.widget.Toolbar
+            android:id="@+id/news_title_bar"
+            android:layout_width="match_parent"
+            android:layout_height="?attr/actionBarSize"
+            android:background="?attr/colorPrimary"
+            app:layout_scrollFlags="scroll|enterAlways" />
+
+        <android.support.design.widget.TabLayout
+            android:id="@+id/date_tab"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            app:tabGravity="fill"
+            app:tabMode="scrollable" />
 
+    </android.support.design.widget.AppBarLayout>
+
+    <android.support.v4.view.ViewPager
+        android:id="@+id/message_pager"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="#ffff"
+        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
 
-    <Button
-        android:id="@+id/button1"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content" />
 
-</LinearLayout>
+</android.support.design.widget.CoordinatorLayout>

+ 28 - 0
news/src/main/res/layout/item_news_list.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:layout_margin="10dp"
+    android:id="@+id/news_layout"
+    android:background="#ffff"
+    android:orientation="horizontal">
+
+    <ImageView
+        android:id="@+id/news_image"
+        android:layout_width="80dp"
+        android:layout_height="80dp"
+        android:background="#eee"
+        tools:src="@mipmap/ic_launcher"
+        tools:ignore="ContentDescription" />
+
+    <TextView
+        android:id="@+id/news_title"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="20dp"
+        android:layout_marginStart="@dimen/size_20dp"
+        android:layout_toEndOf="@+id/news_image"
+        android:layout_toRightOf="@id/news_image"
+        tools:text="张三爱上王麻子" />
+</RelativeLayout>