greenrxnewses = query.list();
109 | if (greenrxnewses != null && greenrxnewses.size() > 0) {
110 | newsModel = AppService.getsGson().fromJson(greenrxnewses.get(0).getNewslist(), NewsModel.class);
111 | }
112 | return newsModel;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/ui/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.ui.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.FloatingActionButton;
5 | import android.support.design.widget.NavigationView;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.v4.view.GravityCompat;
8 | import android.support.v4.widget.DrawerLayout;
9 | import android.support.v7.app.ActionBarDrawerToggle;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.Menu;
12 | import android.view.MenuItem;
13 | import android.view.View;
14 | import android.widget.FrameLayout;
15 | import android.widget.Toast;
16 |
17 | import butterknife.Bind;
18 | import butterknife.ButterKnife;
19 | import opensource.zjt.rxnews.R;
20 | import opensource.zjt.rxnews.base.BaseActivity;
21 | import opensource.zjt.rxnews.ui.fragment.ImageFragment;
22 | import opensource.zjt.rxnews.ui.fragment.NewsFragment;
23 |
24 | public class MainActivity extends BaseActivity
25 | implements NavigationView.OnNavigationItemSelectedListener {
26 |
27 | @Bind(R.id.toolbar)
28 | Toolbar toolbar;
29 | @Bind(R.id.frame_content)
30 | FrameLayout frameContent;
31 | @Bind(R.id.fab)
32 | FloatingActionButton fab;
33 | @Bind(R.id.nav_view)
34 | NavigationView navView;
35 | @Bind(R.id.drawer_layout)
36 | DrawerLayout drawerLayout;
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_main);
42 | ButterKnife.bind(this);
43 | setSupportActionBar(toolbar);
44 |
45 | fab.setOnClickListener(new View.OnClickListener() {
46 | @Override
47 | public void onClick(View view) {
48 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
49 | .setAction("Action", null).show();
50 | }
51 | });
52 |
53 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
54 | this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
55 | drawerLayout.setDrawerListener(toggle);
56 | toggle.syncState();
57 |
58 | navView.setNavigationItemSelectedListener(this);
59 | getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new NewsFragment()).commit();
60 | toolbar.setTitle("新闻");
61 | }
62 |
63 | @Override
64 | public void onBackPressed() {
65 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
66 | if (drawer.isDrawerOpen(GravityCompat.START)) {
67 | drawer.closeDrawer(GravityCompat.START);
68 | } else {
69 | super.onBackPressed();
70 | }
71 | }
72 |
73 | @Override
74 | public boolean onCreateOptionsMenu(Menu menu) {
75 | // Inflate the menu; this adds items to the action bar if it is present.
76 | getMenuInflater().inflate(R.menu.main, menu);
77 | return true;
78 | }
79 |
80 | @Override
81 | public boolean onOptionsItemSelected(MenuItem item) {
82 | // Handle action bar item clicks here. The action bar will
83 | // automatically handle clicks on the Home/Up button, so long
84 | // as you specify a parent activity in AndroidManifest.xml.
85 | int id = item.getItemId();
86 |
87 | //noinspection SimplifiableIfStatement
88 | if (id == R.id.action_settings) {
89 | return true;
90 | }
91 |
92 | return super.onOptionsItemSelected(item);
93 | }
94 |
95 | @SuppressWarnings("StatementWithEmptyBody")
96 | @Override
97 | public boolean onNavigationItemSelected(MenuItem item) {
98 | // Handle navigation view item clicks here.
99 | int id = item.getItemId();
100 |
101 | if (id == R.id.nav_news) {
102 | getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new NewsFragment()).commit();
103 | } else if (id == R.id.nav_picture) {
104 | getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new ImageFragment()).commit();
105 | } else if (id == R.id.nav_blog) {
106 | Toast.makeText(MainActivity.this, getResources().getString(R.string.no_dev), Toast.LENGTH_SHORT).show();
107 | } else if (id == R.id.nav_setting) {
108 | Toast.makeText(MainActivity.this, getResources().getString(R.string.no_dev), Toast.LENGTH_SHORT).show();
109 |
110 | } else if (id == R.id.nav_share) {
111 | Toast.makeText(MainActivity.this, getResources().getString(R.string.no_dev), Toast.LENGTH_SHORT).show();
112 |
113 | } else if (id == R.id.nav_about) {
114 | Toast.makeText(MainActivity.this, getResources().getString(R.string.no_dev), Toast.LENGTH_SHORT).show();
115 |
116 | }
117 |
118 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
119 | drawer.closeDrawer(GravityCompat.START);
120 | return true;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/ui/activity/NewsDetailActivity.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.ui.activity;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.os.Bundle;
5 | import android.support.design.widget.CollapsingToolbarLayout;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.View;
8 | import android.webkit.WebSettings;
9 | import android.webkit.WebView;
10 | import android.widget.ImageView;
11 | import android.widget.ProgressBar;
12 |
13 | import com.bumptech.glide.Glide;
14 |
15 |
16 | import butterknife.Bind;
17 | import butterknife.ButterKnife;
18 | import opensource.zjt.rxnews.R;
19 | import opensource.zjt.rxnews.base.BaseActivity;
20 | import opensource.zjt.rxnews.bean.NewsModel;
21 | import opensource.zjt.rxnews.net.Constant;
22 | import opensource.zjt.rxnews.presenter.NewsDetailPresenter;
23 | import opensource.zjt.rxnews.presenter.NewsDetailPresenterImpl;
24 | import opensource.zjt.rxnews.view.NewsDetailView;
25 |
26 | public class NewsDetailActivity extends BaseActivity implements NewsDetailView {
27 |
28 | @Bind(R.id.ivImage)
29 | ImageView ivImage;
30 | @Bind(R.id.toolbar)
31 | Toolbar toolbar;
32 | @Bind(R.id.collapsing_toolbar)
33 | CollapsingToolbarLayout collapsingToolbar;
34 | @Bind(R.id.progress)
35 | ProgressBar mProgressBar;
36 | @Bind(R.id.detail_webview)
37 | WebView detailWebview;
38 | private NewsModel.NewslistEntity mNews;
39 | private NewsDetailPresenter mNewsDetailPresenter;
40 |
41 | @SuppressLint("SetJavaScriptEnabled")
42 | @Override
43 | protected void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_news_detail);
46 | ButterKnife.bind(this);
47 |
48 | setSupportActionBar(toolbar);
49 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
50 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
51 | @Override
52 | public void onClick(View view) {
53 | onBackPressed();
54 | }
55 | });
56 | detailWebview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
57 | detailWebview.getSettings().setJavaScriptEnabled(true);
58 | detailWebview.setBackgroundColor(0);
59 |
60 | mNews = (NewsModel.NewslistEntity) getIntent().getParcelableExtra(Constant.NEWSDETAIL);
61 |
62 | CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
63 | collapsingToolbar.setTitle(mNews.getTitle());
64 |
65 | Glide.with(this).load(mNews.getPicUrl()).into(ivImage);
66 |
67 | mNewsDetailPresenter = new NewsDetailPresenterImpl(getApplication(), this);
68 | mNewsDetailPresenter.loadNewsDetail(mNews.getUrl());
69 | }
70 |
71 | @Override
72 | public void showNewsDetailContent(String detailUrl) {
73 | detailWebview.loadUrl(detailUrl);
74 | }
75 |
76 | @Override
77 | public void showProgress() {
78 | mProgressBar.setVisibility(View.VISIBLE);
79 | }
80 |
81 | @Override
82 | public void hideProgress() {
83 | mProgressBar.setVisibility(View.GONE);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/ui/fragment/DummyContent.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.ui.fragment;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | /**
9 | * Helper class for providing sample content for user interfaces created by
10 | * Android template wizards.
11 | *
12 | * TODO: Replace all uses of this class before publishing your app.
13 | */
14 | public class DummyContent {
15 |
16 | /**
17 | * An array of sample (dummy) items.
18 | */
19 | public static final List ITEMS = new ArrayList();
20 |
21 | /**
22 | * A map of sample (dummy) items, by ID.
23 | */
24 | public static final Map ITEM_MAP = new HashMap();
25 |
26 | private static final int COUNT = 25;
27 |
28 | static {
29 | // Add some sample items.
30 | for (int i = 1; i <= COUNT; i++) {
31 | addItem(createDummyItem(i));
32 | }
33 | }
34 |
35 | private static void addItem(DummyItem item) {
36 | ITEMS.add(item);
37 | ITEM_MAP.put(item.id, item);
38 | }
39 |
40 | private static DummyItem createDummyItem(int position) {
41 | return new DummyItem(String.valueOf(position), "Item " + position, makeDetails(position));
42 | }
43 |
44 | private static String makeDetails(int position) {
45 | StringBuilder builder = new StringBuilder();
46 | builder.append("Details about Item: ").append(position);
47 | for (int i = 0; i < position; i++) {
48 | builder.append("\nMore details information here.");
49 | }
50 | return builder.toString();
51 | }
52 |
53 | /**
54 | * A dummy item representing a piece of content.
55 | */
56 | public static class DummyItem {
57 | public final String id;
58 | public final String content;
59 | public final String details;
60 |
61 | public DummyItem(String id, String content, String details) {
62 | this.id = id;
63 | this.content = content;
64 | this.details = details;
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return content;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/ui/fragment/ImageAdapter.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.ui.fragment;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import com.bumptech.glide.Glide;
12 |
13 | import java.util.List;
14 |
15 | import opensource.zjt.rxnews.R;
16 | import opensource.zjt.rxnews.bean.ImageModel;
17 |
18 | /**
19 | */
20 | public class ImageAdapter extends RecyclerView.Adapter {
21 |
22 | private List mData;
23 | private Context mContext;
24 |
25 | private OnItemClickListener mOnItemClickListener;
26 |
27 | public ImageAdapter(Context context) {
28 | this.mContext = context;
29 | }
30 |
31 | public void setmDate(List data) {
32 | this.mData = data;
33 | this.notifyDataSetChanged();
34 | }
35 |
36 | @Override
37 | public ImageAdapter.ItemViewHolder onCreateViewHolder(ViewGroup parent,
38 | int viewType) {
39 | View v = LayoutInflater.from(parent.getContext())
40 | .inflate(R.layout.item_image, parent, false);
41 | ItemViewHolder vh = new ItemViewHolder(v);
42 | return vh;
43 | }
44 |
45 | @Override
46 | public void onBindViewHolder(ImageAdapter.ItemViewHolder holder, int position) {
47 | ImageModel.NewsImagelistEntity imageBean = mData.get(position);
48 | if(imageBean == null) {
49 | return;
50 | }
51 | holder.mTitle.setText(imageBean.getTitle());
52 | Glide.with(mContext).load(imageBean.getPicUrl()).into(holder.mImage);
53 | }
54 |
55 | @Override
56 | public int getItemCount() {
57 | if(mData == null) {
58 | return 0;
59 | }
60 | return mData.size();
61 | }
62 |
63 | public ImageModel.NewsImagelistEntity getItem(int position) {
64 | return mData == null ? null : mData.get(position);
65 | }
66 |
67 | public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
68 | this.mOnItemClickListener = onItemClickListener;
69 | }
70 |
71 | public interface OnItemClickListener {
72 | void onItemClick(View view, int position);
73 | }
74 |
75 | public class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
76 |
77 | public TextView mTitle;
78 | public ImageView mImage;
79 |
80 | public ItemViewHolder(View v) {
81 | super(v);
82 | mTitle = (TextView) v.findViewById(R.id.tvTitle);
83 | mImage = (ImageView) v.findViewById(R.id.ivImage);
84 | v.setOnClickListener(this);
85 | }
86 |
87 | @Override
88 | public void onClick(View view) {
89 | if(mOnItemClickListener != null) {
90 | mOnItemClickListener.onItemClick(view, this.getPosition());
91 | }
92 | }
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/ui/fragment/ImageFragment.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.ui.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.widget.SwipeRefreshLayout;
8 | import android.support.v7.widget.DefaultItemAnimator;
9 | import android.support.v7.widget.LinearLayoutManager;
10 | import android.support.v7.widget.RecyclerView;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | import opensource.zjt.rxnews.R;
19 | import opensource.zjt.rxnews.bean.ImageModel;
20 | import opensource.zjt.rxnews.presenter.ImagePresenter;
21 | import opensource.zjt.rxnews.presenter.ImagePresenterImpl;
22 | import opensource.zjt.rxnews.view.ImageViewInterface;
23 |
24 | /**
25 | */
26 | public class ImageFragment extends Fragment implements ImageViewInterface, SwipeRefreshLayout.OnRefreshListener {
27 |
28 | private static final String TAG = "ImageFragment";
29 |
30 | private SwipeRefreshLayout mSwipeRefreshWidget;
31 | private RecyclerView mRecyclerView;
32 | private LinearLayoutManager mLayoutManager;
33 | private ImageAdapter mAdapter;
34 | private List mData;
35 | private ImagePresenter mImagePresenter;
36 |
37 | @Override
38 | public void onCreate(@Nullable Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | mImagePresenter = new ImagePresenterImpl(this);
41 | }
42 |
43 | @Nullable
44 | @Override
45 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
46 | View view = inflater.inflate(R.layout.fragment_image, null);
47 | mSwipeRefreshWidget = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_widget);
48 | mSwipeRefreshWidget.setColorSchemeResources(R.color.colorPrimary,
49 | R.color.colorPrimaryDark, R.color.colorAccent,
50 | R.color.colorAccent);
51 | mSwipeRefreshWidget.setOnRefreshListener(this);
52 |
53 | mRecyclerView = (RecyclerView)view.findViewById(R.id.recycle_view);
54 | mRecyclerView.setHasFixedSize(true);
55 |
56 | mLayoutManager = new LinearLayoutManager(getActivity());
57 | mRecyclerView.setLayoutManager(mLayoutManager);
58 |
59 | mRecyclerView.setItemAnimator(new DefaultItemAnimator());
60 | mAdapter = new ImageAdapter(getActivity().getApplicationContext());
61 | mRecyclerView.setAdapter(mAdapter);
62 | mRecyclerView.setOnScrollListener(mOnScrollListener);
63 | onRefresh();
64 | return view;
65 | }
66 |
67 | private RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() {
68 |
69 | private int lastVisibleItem;
70 |
71 | @Override
72 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
73 | super.onScrolled(recyclerView, dx, dy);
74 | lastVisibleItem = mLayoutManager.findLastVisibleItemPosition();
75 | }
76 |
77 | @Override
78 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
79 | super.onScrollStateChanged(recyclerView, newState);
80 | if (newState == RecyclerView.SCROLL_STATE_IDLE
81 | && lastVisibleItem + 1 == mAdapter.getItemCount() ) {
82 | //加载更多
83 | Snackbar.make(getActivity().findViewById(R.id.drawer_layout), getString(R.string.image_hit), Snackbar.LENGTH_SHORT).show();
84 | }
85 | }
86 | };
87 |
88 | @Override
89 | public void onRefresh() {
90 | if(mData != null) {
91 | mData.clear();
92 | }
93 | mImagePresenter.loadImageList();
94 | }
95 |
96 | @Override
97 | public void addImages(List list) {
98 | if(mData == null) {
99 | mData = new ArrayList();
100 | }
101 | mData.addAll(list);
102 | mAdapter.setmDate(mData);
103 | }
104 |
105 | @Override
106 | public void showProgress() {
107 | mSwipeRefreshWidget.setRefreshing(true);
108 | }
109 |
110 | @Override
111 | public void hideProgress() {
112 | mSwipeRefreshWidget.setRefreshing(false);
113 | }
114 |
115 | @Override
116 | public void showLoadFailMsg() {
117 | View view = getActivity() == null ? mRecyclerView.getRootView() : getActivity().findViewById(R.id.drawer_layout);
118 | Snackbar.make(view, getString(R.string.load_fail), Snackbar.LENGTH_SHORT).show();
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/ui/fragment/MyItemRecyclerViewAdapter.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.ui.fragment;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import com.bumptech.glide.Glide;
12 |
13 | import opensource.zjt.rxnews.R;
14 | import opensource.zjt.rxnews.bean.NewsModel;
15 |
16 | import java.util.List;
17 |
18 | /**
19 | */
20 | public class MyItemRecyclerViewAdapter extends RecyclerView.Adapter {
21 |
22 | private static final int TYPE_ITEM = 0;
23 | private static final int TYPE_FOOTER = 1;
24 |
25 | private List mData;
26 | private boolean mShowFooter = true;
27 | private Context mContext;
28 |
29 | private OnItemClickListener mOnItemClickListener;
30 |
31 | public MyItemRecyclerViewAdapter(Context context) {
32 | this.mContext = context;
33 | }
34 |
35 | public void setmDate(List data) {
36 | this.mData = data;
37 | this.notifyDataSetChanged();
38 | }
39 |
40 | @Override
41 | public int getItemViewType(int position) {
42 | // 最后一个item设置为footerView
43 | if(!mShowFooter) {
44 | return TYPE_ITEM;
45 | }
46 | if (position + 1 == getItemCount()) {
47 | return TYPE_FOOTER;
48 | } else {
49 | return TYPE_ITEM;
50 | }
51 | }
52 |
53 | @Override
54 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
55 | int viewType) {
56 | if(viewType == TYPE_ITEM) {
57 | View v = LayoutInflater.from(parent.getContext())
58 | .inflate(R.layout.fragment_item, parent, false);
59 | ItemViewHolder vh = new ItemViewHolder(v);
60 | return vh;
61 | } else {
62 | View view = LayoutInflater.from(parent.getContext()).inflate(
63 | R.layout.footer, null);
64 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
65 | ViewGroup.LayoutParams.WRAP_CONTENT));
66 | return new FooterViewHolder(view);
67 | }
68 | }
69 |
70 | @Override
71 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
72 | if(holder instanceof ItemViewHolder) {
73 |
74 | NewsModel.NewslistEntity news = mData.get(position);
75 | if(news == null) {
76 | return;
77 | }
78 | ((ItemViewHolder) holder).mTitle.setText(news.getTitle());
79 | ((ItemViewHolder) holder).mDesc.setText(news.getDescription());
80 | Glide.with(mContext).load(news.getPicUrl()).error(R.drawable.ic_image_loadfail).placeholder(R.drawable.ic_image_loading)
81 | .into(((ItemViewHolder) holder).mNewsImg);
82 | }
83 | }
84 |
85 | @Override
86 | public int getItemCount() {
87 | int begin = mShowFooter?1:0;
88 | if(mData == null) {
89 | return begin;
90 | }
91 | return mData.size() + begin;
92 | }
93 |
94 | public NewsModel.NewslistEntity getItem(int position) {
95 | return mData == null ? null : mData.get(position);
96 | }
97 |
98 | public void isShowFooter(boolean showFooter) {
99 | this.mShowFooter = showFooter;
100 | }
101 |
102 | public boolean isShowFooter() {
103 | return this.mShowFooter;
104 | }
105 |
106 | public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
107 | this.mOnItemClickListener = onItemClickListener;
108 | }
109 |
110 | public class FooterViewHolder extends RecyclerView.ViewHolder {
111 |
112 | public FooterViewHolder(View view) {
113 | super(view);
114 | }
115 |
116 | }
117 |
118 | public interface OnItemClickListener {
119 | public void onItemClick(View view, int position);
120 | }
121 |
122 | public class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
123 |
124 | public TextView mTitle;
125 | public TextView mDesc;
126 | public ImageView mNewsImg;
127 |
128 | public ItemViewHolder(View v) {
129 | super(v);
130 | mTitle = (TextView) v.findViewById(R.id.tvTitle);
131 | mDesc = (TextView) v.findViewById(R.id.tvDesc);
132 | mNewsImg = (ImageView) v.findViewById(R.id.ivNews);
133 | v.setOnClickListener(this);
134 | }
135 |
136 | @Override
137 | public void onClick(View view) {
138 | if(mOnItemClickListener != null) {
139 | mOnItemClickListener.onItemClick(view, this.getPosition());
140 | }
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/ui/fragment/NewsFragment.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.ui.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.design.widget.TabLayout;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentPagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 |
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | import butterknife.Bind;
18 | import butterknife.ButterKnife;
19 | import opensource.zjt.rxnews.R;
20 | import opensource.zjt.rxnews.base.AppService;
21 | import opensource.zjt.rxnews.base.BaseFragment;
22 | import opensource.zjt.rxnews.net.Constant;
23 |
24 | /**
25 | * Created by JianTao on 16/1/13.
26 | * Copyright © 2015 impetusconsulting. All rights reserved
27 | */
28 | public class NewsFragment extends BaseFragment {
29 | @Bind(R.id.tab_layout)
30 | TabLayout tabLayout;
31 | @Bind(R.id.viewpager)
32 | ViewPager viewpager;
33 |
34 | @Override
35 | public void onCreate(@Nullable Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | }
38 |
39 | @Nullable
40 | @Override
41 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
42 | super.onCreateView(inflater, container, savedInstanceState);
43 | View view = inflater.inflate(R.layout.fragment_news, null);
44 | ButterKnife.bind(this, view);
45 | viewpager.setOffscreenPageLimit(3);
46 | viewpager.setCurrentItem(0);
47 | setViewPager(viewpager);
48 | tabLayout.setupWithViewPager(viewpager);
49 | return view;
50 | }
51 |
52 | private void setViewPager(ViewPager v) {
53 | MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager());
54 | adapter.addFragment(NewsListFragment.newInstance(0),"科技");
55 | adapter.addFragment(NewsListFragment.newInstance(1),"国际");
56 | adapter.addFragment(NewsListFragment.newInstance(2),"社会");
57 | adapter.addFragment(NewsListFragment.newInstance(3),"体育");
58 | v.setAdapter(adapter);
59 | }
60 |
61 | public static class MyPagerAdapter extends FragmentPagerAdapter {
62 | private final List mFragments = new ArrayList<>();
63 | private final List mFragmentTitles = new ArrayList<>();
64 |
65 | public MyPagerAdapter(FragmentManager fm) {
66 | super(fm);
67 | }
68 |
69 | public void addFragment(Fragment fragment, String title) {
70 | mFragments.add(fragment);
71 | mFragmentTitles.add(title);
72 | }
73 |
74 | @Override
75 | public Fragment getItem(int position) {
76 | return mFragments.get(position);
77 | }
78 |
79 | @Override
80 | public int getCount() {
81 | return mFragments.size();
82 | }
83 |
84 | @Override
85 | public CharSequence getPageTitle(int position) {
86 | return mFragmentTitles.get(position);
87 | }
88 | }
89 |
90 | @Override
91 | public void onDestroyView() {
92 | super.onDestroyView();
93 | ButterKnife.unbind(this);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/ui/fragment/NewsListFragment.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.ui.fragment;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.v4.app.ActivityCompat;
7 | import android.support.v4.app.ActivityOptionsCompat;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.widget.SwipeRefreshLayout;
10 | import android.support.v7.widget.LinearLayoutManager;
11 | import android.support.v7.widget.RecyclerView;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 |
16 | import com.socks.library.KLog;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import butterknife.Bind;
22 | import butterknife.ButterKnife;
23 | import opensource.zjt.rxnews.R;
24 | import opensource.zjt.rxnews.base.AppService;
25 | import opensource.zjt.rxnews.bean.NewsModel;
26 | import opensource.zjt.rxnews.net.Constant;
27 | import opensource.zjt.rxnews.presenter.NewsPresenter;
28 | import opensource.zjt.rxnews.presenter.NewsPresenterImpl;
29 | import opensource.zjt.rxnews.ui.activity.NewsDetailActivity;
30 | import opensource.zjt.rxnews.view.NewsView;
31 |
32 | /**
33 | * A fragment representing a list of Items.
34 | *
35 | */
36 | public class NewsListFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener, NewsView {
37 |
38 | private static final String ARG_COLUMN_COUNT = "column-count";
39 | private static final String TAG = NewsListFragment.class.getName();
40 | @Bind(R.id.recyclerView_list)
41 | RecyclerView recyclerView;
42 | @Bind(R.id.swipe_refresh_widget)
43 | SwipeRefreshLayout mSwipeRefreshWidget;
44 | private int mColumnCount = 1;
45 | private LinearLayoutManager mLayoutManager;
46 | private int pageIndex = 1;
47 | private List mData;
48 | private NewsPresenter mNewsPresenter;
49 |
50 | /**
51 | * Mandatory empty constructor for the fragment manager to instantiate the
52 | * fragment (e.g. upon screen orientation changes).
53 | */
54 | public NewsListFragment() {
55 | }
56 |
57 | // TODO: Customize parameter initialization
58 | @SuppressWarnings("unused")
59 | public static NewsListFragment newInstance(int columnCount) {
60 | NewsListFragment fragment = new NewsListFragment();
61 | Bundle args = new Bundle();
62 | args.putInt(ARG_COLUMN_COUNT, columnCount);
63 | fragment.setArguments(args);
64 | return fragment;
65 | }
66 |
67 | @Override
68 | public void onCreate(Bundle savedInstanceState) {
69 | super.onCreate(savedInstanceState);
70 |
71 | if (getArguments() != null) {
72 | mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
73 | }
74 | AppService.getInstance().initNews(getActivity().getTaskId(), getID(mColumnCount));
75 | }
76 |
77 | @Override
78 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
79 | Bundle savedInstanceState) {
80 | View view = inflater.inflate(R.layout.fragment_item_list, container, false);
81 | ButterKnife.bind(this, view);
82 | mSwipeRefreshWidget.setColorSchemeResources(R.color.colorAccent,
83 | R.color.colorAccent, R.color.colorPrimaryDark,
84 | R.color.colorAccent);
85 | mSwipeRefreshWidget.setOnRefreshListener(this);
86 | mLayoutManager = new LinearLayoutManager(getActivity());
87 |
88 | recyclerView.setLayoutManager(mLayoutManager);
89 | recyclerView.setHasFixedSize(true);
90 | mAdapter = new MyItemRecyclerViewAdapter(getContext().getApplicationContext());
91 | mAdapter.setOnItemClickListener(mOnItemClickListener);
92 | recyclerView.setAdapter(mAdapter);
93 | recyclerView.setOnScrollListener(mOnScrollListener);
94 | mNewsPresenter = new NewsPresenterImpl(this);
95 | onRefresh();
96 | return view;
97 | }
98 |
99 | private MyItemRecyclerViewAdapter mAdapter;
100 | private RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() {
101 |
102 | private int lastVisibleItem;
103 |
104 | @Override
105 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
106 | super.onScrolled(recyclerView, dx, dy);
107 | lastVisibleItem = mLayoutManager.findLastVisibleItemPosition();
108 | }
109 |
110 | @Override
111 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
112 | super.onScrollStateChanged(recyclerView, newState);
113 | if (newState == RecyclerView.SCROLL_STATE_IDLE
114 | && lastVisibleItem + 1 == mAdapter.getItemCount()
115 | && mAdapter.isShowFooter()) {
116 | //加载更多
117 | KLog.d(TAG, "loading more data");
118 | mNewsPresenter.loadNews(mColumnCount, pageIndex++);
119 | }
120 | }
121 | };
122 | private MyItemRecyclerViewAdapter.OnItemClickListener mOnItemClickListener = new MyItemRecyclerViewAdapter.OnItemClickListener() {
123 | @Override
124 | public void onItemClick(View view, int position) {
125 | NewsModel.NewslistEntity news = mAdapter.getItem(position);
126 | Intent intent = new Intent(getActivity(), NewsDetailActivity.class);
127 | intent.putExtra(Constant.NEWSDETAIL, news);
128 | View transitionView = view.findViewById(R.id.ivNews);
129 | ActivityOptionsCompat options =
130 | ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),
131 | transitionView, getString(R.string.transition_news_img));
132 |
133 | ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
134 | }
135 | };
136 |
137 |
138 | @Override
139 | public void onDetach() {
140 | super.onDetach();
141 | }
142 |
143 | @Override
144 | public void onDestroy() {
145 | super.onDestroy();
146 | // ButterKnife.unbind(this);
147 | }
148 |
149 | @Override
150 | public void onRefresh() {
151 | pageIndex = 1;
152 | if (mData != null) {
153 | mData.clear();
154 | }
155 | mNewsPresenter.loadNews(mColumnCount, pageIndex);
156 | }
157 |
158 | @Override
159 | public void addNew(List list) {
160 | mAdapter.isShowFooter(true);
161 | if (mData == null) {
162 | mData = new ArrayList<>();
163 | }
164 | mData.addAll(list);
165 | if (pageIndex == 1) {
166 | mAdapter.setmDate(mData);
167 | } else {
168 | if (list == null || list.size() == 0) {
169 | mAdapter.isShowFooter(false);
170 | }
171 | mAdapter.notifyDataSetChanged();
172 | }
173 | pageIndex += Constant.PAZE_SIZE;
174 | }
175 |
176 | @Override
177 | public void showProgress() {
178 | if (mSwipeRefreshWidget != null)
179 | mSwipeRefreshWidget.setRefreshing(true);
180 | }
181 |
182 | @Override
183 | public void hideProgress() {
184 | if (mSwipeRefreshWidget != null)
185 | mSwipeRefreshWidget.setRefreshing(false);
186 | }
187 |
188 | @Override
189 | public void showLoadFail() {
190 | if (pageIndex == 1) {
191 | mAdapter.isShowFooter(false);
192 | mAdapter.notifyDataSetChanged();
193 | }
194 | View view = getActivity() == null ? recyclerView.getRootView() : getActivity().findViewById(R.id.drawer_layout);
195 | Snackbar.make(view, getString(R.string.load_fail), Snackbar.LENGTH_SHORT).show();
196 | }
197 |
198 | private String getID(int type) {
199 | String id;
200 | switch (type) {
201 | case 0:
202 | id = Constant.NEWSTYPE_KEJI;
203 | break;
204 | case 1:
205 | id = Constant.NEWSTYPE_GUOJI;
206 | break;
207 | case 2:
208 | id = Constant.NEWSTYPE_SHEHUI;
209 | break;
210 | case 3:
211 | id = Constant.NEWSTYPE_TIYU;
212 | break;
213 | default:
214 | id = Constant.NEWSTYPE_KEJI;
215 | break;
216 | }
217 | return id;
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/utils/AppUtils.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.utils;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageManager;
5 | import android.content.res.Resources;
6 | import android.graphics.Color;
7 | import android.net.ConnectivityManager;
8 | import android.net.NetworkInfo;
9 | import android.support.design.widget.Snackbar;
10 | import android.view.View;
11 | import android.widget.TextView;
12 |
13 | import opensource.zjt.rxnews.R;
14 | import opensource.zjt.rxnews.base.BaseApplication;
15 |
16 |
17 | /**
18 | */
19 | public class AppUtils {
20 |
21 | public static String getVersionName(Context context) {
22 | String versionName = null;
23 | try {
24 | versionName = context.getApplicationContext().getPackageManager()
25 | .getPackageInfo(context.getApplicationContext().getPackageName(), 0).versionName;
26 | } catch (PackageManager.NameNotFoundException e) {
27 | e.printStackTrace();
28 | }
29 | return versionName;
30 | }
31 |
32 |
33 | public static void showSnackBar(View view, int id) {
34 | Resources resources = BaseApplication.getmContext().getResources();
35 | Snackbar sb = Snackbar.make(view, resources.getString(id), Snackbar.LENGTH_SHORT);
36 | setSnackbarMessageTextColor(sb);
37 | sb.getView().setBackgroundColor(resources.getColor(R.color.main_bg));
38 | sb.show();
39 | }
40 |
41 | public static void setSnackbarMessageTextColor(Snackbar snackbar) {
42 | View view = snackbar.getView();
43 | ((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(Color.parseColor("#448AFF"));
44 | }
45 |
46 | /**
47 | * 判断网络是否可用
48 | *
49 | * @param context Context对象
50 | */
51 | public static Boolean isNetworkReachable(Context context) {
52 | ConnectivityManager cm = (ConnectivityManager) context
53 | .getSystemService(Context.CONNECTIVITY_SERVICE);
54 | NetworkInfo current = cm.getActiveNetworkInfo();
55 | if (current == null) {
56 | return false;
57 | }
58 | return (current.isAvailable());
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/view/ImageViewInterface.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.view;
2 |
3 | import java.util.List;
4 |
5 | import opensource.zjt.rxnews.bean.ImageModel;
6 |
7 | public interface ImageViewInterface {
8 | void addImages(List list);
9 |
10 | void showProgress();
11 |
12 | void hideProgress();
13 |
14 | void showLoadFailMsg();
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/view/NewsDetailView.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.view;
2 |
3 | /**
4 | * Created by JianTao on 16/1/21.
5 | * Copyright © 2015 impetusconsulting. All rights reserved
6 | */
7 | public interface NewsDetailView {
8 | void showNewsDetailContent(String detailurl);
9 |
10 | void showProgress();
11 |
12 | void hideProgress();
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/opensource/zjt/rxnews/view/NewsView.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews.view;
2 |
3 | import java.util.List;
4 |
5 | import opensource.zjt.rxnews.bean.NewsModel;
6 |
7 | /**
8 | * Created by JianTao on 16/1/21.
9 | * Copyright © 2015 impetusconsulting. All rights reserved
10 | */
11 | public interface NewsView {
12 | void addNew(List list);
13 |
14 | void showProgress();
15 |
16 | void hideProgress();
17 |
18 | void showLoadFail();
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_camera.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/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/drawable-v21/ic_menu_send.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_share.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_slideshow.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_image_loadfail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiantao88/RxNews/0fb3bfe2219caac704543a4c1a62803362ce2dd0/app/src/main/res/drawable-xxhdpi/ic_image_loadfail.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_image_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiantao88/RxNews/0fb3bfe2219caac704543a4c1a62803362ce2dd0/app/src/main/res/drawable-xxhdpi/ic_image_loading.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/side_nav_bar.xml:
--------------------------------------------------------------------------------
1 |
3 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_news_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
23 |
24 |
33 |
34 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
52 |
53 |
57 |
63 |
64 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/app_bar_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
32 |
33 |
34 |
35 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/footer.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
23 |
24 |
29 |
30 |
38 |
39 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_item_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_news.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
19 |
20 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
25 |
26 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_header_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
27 |
28 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_main_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiantao88/RxNews/0fb3bfe2219caac704543a4c1a62803362ce2dd0/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiantao88/RxNews/0fb3bfe2219caac704543a4c1a62803362ce2dd0/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiantao88/RxNews/0fb3bfe2219caac704543a4c1a62803362ce2dd0/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiantao88/RxNews/0fb3bfe2219caac704543a4c1a62803362ce2dd0/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiantao88/RxNews/0fb3bfe2219caac704543a4c1a62803362ce2dd0/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #212121
8 | #727272
9 | #eceff1
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 160dp
5 |
6 | 16dp
7 | 16dp
8 | 16dp
9 | 16dp
10 | 16sp
11 | 12sp
12 | 5dp
13 |
14 |
--------------------------------------------------------------------------------
/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/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RxNews
3 |
4 | Open navigation drawer
5 | Close navigation drawer
6 |
7 | Settings
8 | transition_news_img
9 | 加载失败
10 |
11 |
12 | Hello blank fragment
13 | 加载更多
14 | 暂未实现
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/test/java/opensource/zjt/rxnews/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package opensource.zjt.rxnews;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 |
19 | maven {
20 | url "http://maven.bughd.com/public"
21 |
22 | }
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/rxnew_greendao/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/rxnew_greendao/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | dependencies {
4 | compile fileTree(dir: 'libs', include: ['*.jar'])
5 | compile 'de.greenrobot:greendao-generator:2.0.0'
6 | }
--------------------------------------------------------------------------------
/rxnew_greendao/src/main/java/com/example/DaoGeneration.java:
--------------------------------------------------------------------------------
1 | package com.example;
2 |
3 | import de.greenrobot.daogenerator.DaoGenerator;
4 | import de.greenrobot.daogenerator.Entity;
5 | import de.greenrobot.daogenerator.Schema;
6 |
7 | public class DaoGeneration {
8 | public static void main(String[] args) throws Exception {
9 |
10 | Schema schema = new Schema(1, "com.rxnews.greendao");
11 | addNews(schema);
12 | new DaoGenerator().generateAll(schema, "/Users/Adele/AndroidDemo/RxNews/app/src/main/java-gen");
13 | }
14 | public static void addNews(Schema schema){
15 | Entity news = schema.addEntity("Greenrxnews");
16 | news.addIdProperty();
17 | news.addStringProperty("newslist");
18 | news.addStringProperty("type");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':rxnew_greendao'
2 |
--------------------------------------------------------------------------------