Skip to content

Commit

Permalink
新闻列表实现;
Browse files Browse the repository at this point in the history
  • Loading branch information
aishang5wpj committed May 17, 2016
1 parent 206cf42 commit c5031fa
Show file tree
Hide file tree
Showing 37 changed files with 643 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified SwipebackLayout/build/intermediates/bundles/debug/classes.jar
Binary file not shown.
Binary file modified SwipebackLayout/build/intermediates/bundles/release/classes.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified SwipebackLayout/build/outputs/aar/SwipebackLayout-debug.aar
Binary file not shown.
Binary file modified SwipebackLayout/build/outputs/aar/SwipebackLayout-release.aar
Binary file not shown.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ dependencies {
compile 'com.facebook.fresco:fresco:0.9.0+'
compile 'com.android.support:recyclerview-v7:23.+'
compile project(':SwipebackLayout')
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.aishang5wpj.juhenews;

import android.test.AndroidTestCase;

import com.aishang5wpj.juhenews.utils.FileUtils;

/**
* Created by wpj on 16/5/17上午11:42.
*/
public class FileUtilsTest extends AndroidTestCase {

@Override
public void testAndroidTestCaseSetupProperly() {
super.testAndroidTestCaseSetupProperly();

String result = FileUtils.readAssertsFile(mContext, "channel.json");
assertNotNull(result);
result = FileUtils.readAssertsFile(mContext, "test/test.json");
assertNotNull(result);
}
}
66 changes: 66 additions & 0 deletions app/src/main/assets/channel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"showapi_res_code": 0,
"showapi_res_error": "",
"showapi_res_body": {
"channelList": [
{
"channelId": "5572a108b3cdc86cf39001cd",
"name": "国内焦点"
},
{
"channelId": "5572a108b3cdc86cf39001ce",
"name": "国际焦点"
},
{
"channelId": "5572a108b3cdc86cf39001cf",
"name": "军事焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d0",
"name": "财经焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d1",
"name": "互联网焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d2",
"name": "房产焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d3",
"name": "汽车焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d4",
"name": "体育焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d5",
"name": "娱乐焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d6",
"name": "游戏焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d7",
"name": "教育焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d8",
"name": "女人焦点"
},
{
"channelId": "5572a108b3cdc86cf39001d9",
"name": "科技焦点"
},
{
"channelId": "5572a109b3cdc86cf39001da",
"name": "社会焦点"
}
],
"ret_code": 0,
"totalNum": 44
}
}
1 change: 1 addition & 0 deletions app/src/main/assets/test/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a test file.
71 changes: 71 additions & 0 deletions app/src/main/java/com/aishang5wpj/juhenews/bean/NewsBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.aishang5wpj.juhenews.bean;

import java.util.ArrayList;
import java.util.List;

/**
* Created by wpj on 16/5/17上午10:27.
*/
public class NewsBean {

public String showapi_res_code = "";
public String showapi_res_error = "";
public Body showapi_res_body;

public NewsBean() {
showapi_res_body = new Body();
}

public class Body {
public String ret_code = "";
public Page pagebean;

public Body() {
pagebean = new Page();
}
}

public class Page {
public String allNum = "";
public String allPages = "";
public String currentPage = "";
public String maxResult = "";
public List<News> contentlist;

public Page() {
contentlist = new ArrayList<>(1);
}
}

public class News {
public String channelId = "";
public String channelName = "";
public String content = "";
public String desc = "";
public String html = "";
public List<Image> imageurls;
public String link = "";
public String nid = "";
public String pubDate = "";//发表时间
public String sentiment_display = "";
public String source = "";//新闻来源
public String title = "";//

public News() {
imageurls = new ArrayList<>(1);
}

public String getImageUrl() {
if (null == imageurls || imageurls.size() <= 0) {
return "";
}
return imageurls.get(0).url;
}
}

public class Image {
public String height = "";
public String url = "";
public String width = "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.aishang5wpj.juhenews.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
* Created by wpj on 16/5/17下午1:16.
*/
public class NewsChannelBean {
public String showapi_res_code = "";
public String showapi_res_error = "";
public Body showapi_res_body;

public NewsChannelBean() {
showapi_res_body = new Body();
}

public class Body {
public String ret_code = "";
public String totalNum = "";
public List<Channel> channelList;

public Body() {
channelList = new ArrayList<>(1);
}
}

public class Channel implements Serializable {
public String channelId = "";
public String name = "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.aishang5wpj.juhenews.main.news;

import android.content.Context;

import com.aishang5wpj.juhenews.bean.NewsChannelBean;

/**
* Created by wpj on 16/5/17下午1:30.
*/
public interface INewsChannelView {

void onLoadChannelCompleted(NewsChannelBean channelBean);

void runOnUiThread(Runnable runnable);

Context getContext();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.aishang5wpj.juhenews.main.news;

import com.aishang5wpj.juhenews.bean.NewsBean;
import com.aishang5wpj.juhenews.bean.NewsChannelBean;

/**
* Created by wpj on 16/5/17上午10:08.
*/
public interface INewsModel {

void loadChannel(OnLoadChannelListener listener);

void loadNews(NewsChannelBean.Channel channel, int page, OnLoadNewsListener listener);

interface OnLoadChannelListener {
void onLoadCompleted(NewsChannelBean channelBean);
}

interface OnLoadNewsListener {
void onLoadCompleted(NewsBean newsBean);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.aishang5wpj.juhenews.main.news;

import com.aishang5wpj.juhenews.bean.NewsChannelBean;

/**
* Created by wpj on 16/5/17上午10:05.
*/
public interface INewsPresenter {

void loadNews(NewsChannelBean.Channel channel, int page);

void loadChannel();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.aishang5wpj.juhenews.main.news;

import com.aishang5wpj.juhenews.bean.NewsBean;

/**
* Created by wpj on 16/5/17上午10:09.
*/
public interface INewsView {
void showProgress();

void hideProgress();

void onNewsLoad(NewsBean newsBean);

void runOnUiThread(Runnable runnable);
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
package com.aishang5wpj.juhenews.main.news;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.aishang5wpj.juhenews.R;
import com.aishang5wpj.juhenews.app.BaseFragment;
import com.aishang5wpj.juhenews.bean.NewsChannelBean;

import java.util.ArrayList;
import java.util.List;

/**
* Created by wpj on 16/5/16上午10:41.
*/
public class NewsFragment extends BaseFragment {

/**
* http://apistore.baidu.com/apiworks/servicedetail/688.html
*/
public static final int NEWS_RECOMMEND = 0;
/**
* http://apistore.baidu.com/apiworks/servicedetail/632.html
*/
public static final int NEWS_WEI_XIN = 1;
/**
* http://apistore.baidu.com/apiworks/servicedetail/868.html
*/
public static final int NEWS_SOCIETY = 2;
/**
* http://apistore.baidu.com/apiworks/servicedetail/1061.html
*/
public static final int NEWS_TECHNOLOGY = 3;
/***
* http://apistore.baidu.com/apiworks/servicedetail/711.html
*/
public static final int NEWS_SPORT = 4;
public class NewsFragment extends BaseFragment implements INewsChannelView {

private TabLayout mTabLayout;
private ViewPager mViewPager;
private NewsPagerAdpater mPagerAdpater;
private NewsPresenterImpl mNewsPresenter;

@Override
protected int getLayoutId() {
Expand All @@ -56,25 +42,39 @@ public void onInitListeners() {
@Override
public void onInitData() {
mPagerAdpater = new NewsPagerAdpater(getChildFragmentManager());
mPagerAdpater.addFragment(NewsListFragment.newInstance(NEWS_RECOMMEND), getString(R.string.news_recommend));
mPagerAdpater.addFragment(NewsListFragment.newInstance(NEWS_WEI_XIN), getString(R.string.news_weixin));
mPagerAdpater.addFragment(NewsListFragment.newInstance(NEWS_SOCIETY), getString(R.string.news_society));
mPagerAdpater.addFragment(NewsListFragment.newInstance(NEWS_TECHNOLOGY), getString(R.string.news_technology));
mPagerAdpater.addFragment(NewsListFragment.newInstance(NEWS_SPORT), getString(R.string.news_sport));

mViewPager.setAdapter(mPagerAdpater);
mViewPager.setOffscreenPageLimit(4);

mTabLayout.addTab(mTabLayout.newTab().setText(R.string.news_recommend));
mTabLayout.addTab(mTabLayout.newTab().setText(R.string.news_weixin));
mTabLayout.addTab(mTabLayout.newTab().setText(R.string.news_society));
mTabLayout.addTab(mTabLayout.newTab().setText(R.string.news_technology));
mTabLayout.addTab(mTabLayout.newTab().setText(R.string.news_sport));
mTabLayout.setupWithViewPager(mViewPager);

mNewsPresenter = new NewsPresenterImpl(this);
mNewsPresenter.loadChannel();
}

@Override
public void onClick(View v) {

}

@Override
public void onLoadChannelCompleted(NewsChannelBean channelBean) {

mPagerAdpater.clear();
mTabLayout.removeAllTabs();

List<Fragment> fragmentList = new ArrayList<>();
List<String> nameList = new ArrayList<>();
List<NewsChannelBean.Channel> channelList = channelBean.showapi_res_body.channelList;
for (NewsChannelBean.Channel channel : channelList) {

fragmentList.add(NewsListFragment.newInstance(channel));
nameList.add(channel.name);
mTabLayout.addTab(mTabLayout.newTab().setText(channel.name));
}
mPagerAdpater.setData(fragmentList, nameList);
mViewPager.setOffscreenPageLimit(channelList.size() - 1);
}

@Override
public void runOnUiThread(Runnable runnable) {
getActivity().runOnUiThread(runnable);
}
}
Loading

0 comments on commit c5031fa

Please sign in to comment.