tasteVos);
33 |
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/basevo/NewsVo.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.basevo;
2 |
3 |
4 | import cn.edu.hpu.yuan.yuannews.main.data.model.base.News;
5 |
6 | /**
7 | * Created by yuan on 16-3-30.
8 | * 客户实体类
9 | */
10 | public class NewsVo extends News {
11 |
12 | private Integer cid;
13 | private Integer sid;
14 |
15 | public Integer getCid() {
16 | return cid;
17 | }
18 |
19 | public void setCid(Integer cid) {
20 | this.cid = cid;
21 | }
22 |
23 | public Integer getSid() {
24 | return sid;
25 | }
26 |
27 | public void setSid(Integer sid) {
28 | this.sid = sid;
29 | }
30 |
31 | @Override
32 | public String toString() {
33 | return super.toString();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/news/TuijianModel.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.news;
2 |
3 |
4 | /**
5 | * ==================================================
6 | *
7 | * 通知推荐的model , 显示数量和 第一条新的新闻
8 | *
9 | * ==================================================
10 | */
11 | public class TuijianModel {
12 |
13 | private Integer count;
14 |
15 | private NewsCustom newsCustom;
16 |
17 | public Integer getCount() {
18 | return count;
19 | }
20 |
21 | public void setCount(Integer count) {
22 | this.count = count;
23 | }
24 |
25 | public NewsCustom getNewsCustom() {
26 | return newsCustom;
27 | }
28 |
29 | public void setNewsCustom(NewsCustom newsCustom) {
30 | this.newsCustom = newsCustom;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/comment/CommenContancts.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.comment;
2 |
3 | import java.util.ArrayList;
4 |
5 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.CommentJo;
6 |
7 | /**
8 | * Created by yuan on 16-5-13.
9 | */
10 | public interface CommenContancts {
11 |
12 | interface CommenContanctsPresenter{
13 |
14 | void initLoadCommentData(int nid);
15 |
16 | void nextLoadCommentData(int nid);
17 |
18 | //用户评论
19 | void userCommenData(String content,Integer nid);
20 | }
21 |
22 | interface CommenContanctsView{
23 | void showDialog();
24 |
25 | void showComentData(ArrayList comments);
26 |
27 | void showErrorMsg(String msg);
28 |
29 | void showSuccess();
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/login/LoginModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.login;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 |
6 | /**
7 | * Created by yuan on 16-5-12.
8 | */
9 | @Module
10 | public class LoginModule {
11 |
12 |
13 | protected LoginContract.LoginContractView loginContractView;
14 |
15 | public LoginModule() {
16 | }
17 |
18 | public LoginModule(LoginContract.LoginContractView loginContractView) {
19 | this.loginContractView = loginContractView;
20 | }
21 |
22 | @Provides
23 | LoginFragment provideLoginFragment(){
24 | return new LoginFragment();
25 | }
26 |
27 | @Provides
28 | LoginContract.LoginContractPresenter provideLoginContractPresenter(){
29 | return new LoginPresenter(loginContractView);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/userIfo/UserIfoModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.userIfo;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 |
6 | /**
7 | * Created by yuan on 16-5-12.
8 | */
9 | @Module
10 | public class UserIfoModule {
11 |
12 | public UserIfoModule(){}
13 |
14 | protected UserIfoContrancts.UserIfoContranctsView userIfoContranctsView;
15 |
16 | public UserIfoModule(UserIfoContrancts.UserIfoContranctsView userIfoContranctsView) {
17 | this.userIfoContranctsView = userIfoContranctsView;
18 | }
19 |
20 | @Provides
21 | UserIfoFragment provideUserIfoFragment(){
22 | return new UserIfoFragment();
23 | }
24 |
25 | @Provides
26 | UserIfoContrancts.UserIfoContranctsPresenter provideUserContranctsPresenter(){
27 | return new UserIfoPresenter(userIfoContranctsView);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/basevo/LikedVo.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.basevo;
2 |
3 | import cn.edu.hpu.yuan.yuannews.main.data.model.base.Liked;
4 |
5 | /**
6 | * Created by yuan on 16-4-3.
7 | * 留言拓展类
8 | */
9 | public class LikedVo extends Liked {
10 |
11 | private Integer uid;
12 | private String head;
13 | private String nick;
14 |
15 | public Integer getUid() {
16 | return uid;
17 | }
18 |
19 | public void setUid(Integer uid) {
20 | this.uid = uid;
21 | }
22 |
23 | public String getHead() {
24 | return head;
25 | }
26 |
27 | public void setHead(String head) {
28 | this.head = head;
29 | }
30 |
31 | public String getNick() {
32 | return nick;
33 | }
34 |
35 | public void setNick(String nick) {
36 | this.nick = nick;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/main/MainContract.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.main;
2 |
3 | import android.support.v4.app.Fragment;
4 |
5 | import java.util.List;
6 |
7 | import cn.edu.hpu.yuan.yuannews.main.base.BasePresenter;
8 | import cn.edu.hpu.yuan.yuannews.main.base.BaseView;
9 |
10 | /**
11 | * Created by yuan on 16-5-10.
12 | * 包括Presenter和View接口
13 | */
14 | public interface MainContract {
15 |
16 |
17 | interface MainPresenter extends BasePresenter{
18 |
19 | void loadDataRequest();
20 | }
21 |
22 | interface MainView extends BaseView{
23 |
24 | void showLoadDialog(); //加载数据
25 |
26 | void showLoadData(List fragments,List titles);//返回数据到主界面
27 |
28 | void finishLoadDialog(); //停止加载
29 |
30 | void loadError();
31 |
32 | void loadMsg(String msg);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/register/RegisterModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.register;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 |
6 | /**
7 | * Created by yuan on 16-5-12.
8 | */
9 |
10 | @Module
11 | public class RegisterModule {
12 |
13 |
14 | protected RegisterContancts.RegisterCOntanctsView registerCOntanctsView;
15 |
16 | public RegisterModule(RegisterContancts.RegisterCOntanctsView registerCOntanctsView) {
17 | this.registerCOntanctsView = registerCOntanctsView;
18 | }
19 |
20 | public RegisterModule() {
21 | }
22 |
23 | @Provides
24 | RegisterFragment provideRegisterFragment(){
25 | return new RegisterFragment();
26 | }
27 |
28 | @Provides
29 | RegisterContancts.RegisterContanctsPresenter provideRegsiterPresenter(){
30 | return new RegisterPresenter(registerCOntanctsView);
31 | }
32 |
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/basevo/TasteVo.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.basevo;
2 |
3 |
4 |
5 | import cn.edu.hpu.yuan.yuannews.main.data.model.base.Taste;
6 |
7 | /**
8 | * Created by yuan on 16-4-1.
9 | * 兴趣拓展类
10 | */
11 | public class TasteVo extends Taste {
12 |
13 | private Integer uid;
14 | private String nick;
15 |
16 | public Integer getUid() {
17 | return uid;
18 | }
19 |
20 | public void setUid(Integer uid) {
21 | this.uid = uid;
22 | }
23 |
24 | public String getNick() {
25 | return nick;
26 | }
27 |
28 | public void setNick(String nick) {
29 | this.nick = nick;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return super.toString()+"TasteVo{" +
35 | "uid=" + uid +
36 | ", nick='" + nick + '\'' +
37 | '}';
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/other/AboutFragment.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.other;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import cn.edu.hpu.yuan.yuannews.R;
10 | import cn.edu.hpu.yuan.yuannews.main.base.NorbalBackFragment;
11 |
12 | /**
13 | * Created by yuan on 16-5-13.
14 | */
15 | public class AboutFragment extends NorbalBackFragment{
16 |
17 | @Nullable
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
20 | return inflater.inflate(R.layout.about_activity,container,false);
21 | }
22 |
23 | @Override
24 | protected void initView(View view, Bundle savedInstanceState) {
25 |
26 | }
27 |
28 | @Override
29 | protected void initComponent() {
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/userIfo/UserIfoFragment.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.userIfo;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import cn.edu.hpu.yuan.yuannews.main.base.NorbalBackFragment;
7 |
8 | /**
9 | * Created by yuan on 16-5-12.
10 | */
11 | public class UserIfoFragment extends NorbalBackFragment implements UserIfoContrancts.UserIfoContranctsView{
12 |
13 |
14 | @Override
15 | protected void initView(View view, Bundle savedInstanceState) {
16 |
17 | }
18 |
19 | @Override
20 | protected void initComponent() {
21 |
22 | DaggerUserifoComponent
23 | .builder()
24 | .userIfoModule(new UserIfoModule(this))
25 | .build()
26 | .injectUserIfoFragment(this);
27 |
28 | }
29 |
30 | @Override
31 | public void showDialog() {
32 |
33 | }
34 |
35 | @Override
36 | public void showMsg(String msg) {
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/base/NormalBackActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.base;
2 |
3 | import android.support.design.widget.FloatingActionButton;
4 | import android.support.v7.widget.Toolbar;
5 | import android.view.View;
6 |
7 | import cn.edu.hpu.yuan.yuannews.R;
8 |
9 | /**
10 | * Created by yuan on 16-5-11.
11 | */
12 | public abstract class NormalBackActivity extends BaseActivity{
13 |
14 |
15 | @Override
16 | protected void initToolbar(Toolbar toolbar, FloatingActionButton floatingActionButton) {
17 | super.initToolbar(toolbar,floatingActionButton);
18 | floatingActionButton.setVisibility(View.GONE);
19 | toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
20 | toolbar.setTitle("新闻详情");
21 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
22 | @Override
23 | public void onClick(View v) {
24 | onBackPressed();
25 | }
26 | });
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/userIfo/UserIfoPresenter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.userIfo;
2 |
3 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
4 |
5 | /**
6 | * Created by yuan on 16-5-12.
7 | */
8 | public class UserIfoPresenter implements UserIfoContrancts.UserIfoContranctsPresenter{
9 |
10 | private int uid;
11 | private UserIfoContrancts.UserIfoContranctsView userIfoContranctsView;
12 | public UserIfoPresenter(UserIfoContrancts.UserIfoContranctsView userIfoContranctsView) {
13 | this.userIfoContranctsView = userIfoContranctsView;
14 | uid= BaseApplication.newsAPIShared.getSharedUserID();
15 | }
16 |
17 | @Override
18 | public void postUpdateUserNick(String nick) {
19 |
20 | }
21 |
22 | @Override
23 | public void postUpdateUserSex(Integer sex) {
24 |
25 | }
26 |
27 | @Override
28 | public void postUpdateUserPass(String pass) {
29 |
30 | }
31 |
32 | @Override
33 | public void postUpdateUserHead() {
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/main_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/newslist/NewsContract.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.newslist;
2 |
3 | import java.util.ArrayList;
4 |
5 | import cn.edu.hpu.yuan.yuannews.main.base.BasePresenter;
6 | import cn.edu.hpu.yuan.yuannews.main.base.BaseView;
7 | import cn.edu.hpu.yuan.yuannews.main.data.model.news.NewsCustom;
8 |
9 | /**
10 | * Created by yuan on 16-5-9.
11 | * 新闻列表类
12 | * 1.Presenter接口
13 | * 2.View接口
14 | */
15 | public interface NewsContract {
16 |
17 | interface Presenter extends BasePresenter {
18 |
19 | //初始化
20 | void initNewsListData(String title,int type,int nType);
21 |
22 | //下一页
23 | void nextNewsListData(String title,int type,int nType);
24 |
25 | }
26 |
27 | interface View extends BaseView {
28 |
29 | void showDialog();
30 |
31 | void showNewsList(ArrayList newsCustoms);
32 |
33 | void showInitNewsList(); //第一页
34 |
35 | void dismssDiolog();
36 |
37 | void showNotData();//完成
38 |
39 | void showSnackBar(String msg);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/DataBean.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model;
2 |
3 | /**
4 | * ==================================================
5 | *
6 | * 版权: 软件工程.net12-1 原明卓
7 | *
8 | * 项目: 基于用户兴趣标签的新闻推荐系统
9 | *
10 | * 作者: 原明卓
11 | *
12 | * 版本: 1.0
13 | *
14 | * 创建日期: 16-5-5 下午3:45
15 | *
16 | * 功能描述: 数据封装bean:返回有状态码,响应信息,和数据的bean
17 | *
18 | *
19 | * 功能更新历史:
20 | *
21 | * ==================================================
22 | */
23 | public class DataBean {
24 |
25 | private int code;
26 | private String msg="成功";
27 | private T data;
28 |
29 | public int getCode() {
30 | return code;
31 | }
32 |
33 | public void setCode(int code) {
34 | this.code = code;
35 | }
36 |
37 | public String getMsg() {
38 | return msg;
39 | }
40 |
41 | public void setMsg(String msg) {
42 | this.msg = msg;
43 | }
44 |
45 | public T getData() {
46 | return data;
47 | }
48 |
49 | public void setData(T data) {
50 | this.data = data;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/newsdetail/NewsDetailContancts.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.newsdetail;
2 |
3 | import java.util.List;
4 |
5 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.LikedVo;
6 | import cn.edu.hpu.yuan.yuannews.main.data.model.news.NewsCustom;
7 |
8 | /**
9 | * Created by yuan on 16-5-11.
10 | * Presenter
11 | */
12 | public interface NewsDetailContancts {
13 |
14 |
15 | interface NewsDetailPresenter{
16 |
17 | void getNewsDetailData(int nid);
18 |
19 | void updateNewsZan(int nid,int status);
20 |
21 | void getNewsZansHeadData(int nid);
22 |
23 | void getNewsZanStatus(int nid);
24 | }
25 |
26 | interface NewsDetailView{
27 |
28 | void showDialog();
29 |
30 | void getNewsDetail(NewsCustom newsCustom);
31 |
32 | void loadError();
33 |
34 | void dimssDialog();
35 |
36 | void updateZanSuccess();
37 |
38 | void updateZanError();
39 |
40 | void getZansHead(List likedVos);
41 |
42 | void getZansHeadError();
43 |
44 | void getZanStatus(int status);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/menu/drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/other/AboutActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.other;
2 |
3 | import android.support.v7.widget.Toolbar;
4 | import android.view.View;
5 |
6 | import cn.edu.hpu.yuan.yuannews.R;
7 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
8 | import cn.edu.hpu.yuan.yuannews.main.base.NormalBaseActivity;
9 |
10 | /**
11 | * Created by yuan on 16-5-13.
12 | */
13 | public class AboutActivity extends NormalBaseActivity{
14 |
15 | @Override
16 | protected void initView() {
17 | }
18 |
19 | @Override
20 | protected void setComponet() {
21 |
22 | }
23 |
24 | @Override
25 | protected void initToolbar(Toolbar toolbar) {
26 | setTitle("关于");
27 | toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
28 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
29 | @Override
30 | public void onClick(View v) {
31 | onBackPressed();
32 | }
33 | });
34 | }
35 |
36 | @Override
37 | protected BaseFragment initFragment() {
38 | return new AboutFragment();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/label/LabelModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.label;
2 |
3 | import android.content.Context;
4 |
5 | import cn.edu.hpu.yuan.yuannews.user.label.adapter.LabelIfoAdapter;
6 | import dagger.Module;
7 | import dagger.Provides;
8 |
9 | /**
10 | * Created by yuan on 16-5-12.
11 | */
12 | @Module
13 | public class LabelModule {
14 |
15 | public LabelModule(){}
16 |
17 | LabelContancts.LabelContanctsView labelContanctsView;
18 | private Context context;
19 |
20 | public LabelModule(LabelContancts.LabelContanctsView labelContanctsView, Context context) {
21 | this.labelContanctsView = labelContanctsView;
22 | this.context=context;
23 | }
24 |
25 | @Provides
26 | LabelFragment provideLabelFragment(){
27 | return new LabelFragment();
28 | }
29 |
30 |
31 | @Provides
32 | LabelContancts.LabelContanctsPresenter provideLabelContractsPresenter(){
33 | return new LabelPresenter(labelContanctsView);
34 | }
35 |
36 | @Provides
37 | LabelIfoAdapter provideLabelIfoAdapter(){
38 | return new LabelIfoAdapter(context);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/app/ApplicationModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.app;
2 |
3 |
4 |
5 | import android.content.Context;
6 |
7 | import javax.inject.Singleton;
8 |
9 | import cn.edu.hpu.yuan.yuancore.util.CrashHandler;
10 | import cn.edu.hpu.yuan.yuannews.main.util.NotificationUtil;
11 | import dagger.Module;
12 | import dagger.Provides;
13 |
14 | /**
15 | * Created by yuan on 16-5-9.
16 | * 为BaseApplication提供实例
17 | * 1.提供Application的Context
18 | * 2.提供CrashHandler类
19 | * 3.等等 数据API等
20 | * 4.提供通知util 工具类
21 | */
22 |
23 | @Module
24 | public class ApplicationModule {
25 |
26 | protected Context context;
27 |
28 | public ApplicationModule(Context context) {
29 | this.context = context;
30 | }
31 |
32 | @Provides @Singleton
33 | public Context provideContext(){
34 | return context;
35 | }
36 |
37 | @Provides @Singleton
38 | public CrashHandler provideCrashHandler(){
39 | return CrashHandler.getInstance();
40 | }
41 |
42 | @Provides @Singleton
43 | public NotificationUtil provideNotification(){
44 | return NotificationUtil.newInstance(context);
45 | }
46 |
47 |
48 |
49 | //等等
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/news/CSCustom.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.news;
2 |
3 |
4 | import java.util.List;
5 |
6 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.CateVo;
7 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.SourceVo;
8 |
9 | /**
10 | * ==================================================
11 | *
12 | * 版权: 软件工程.net12-1 原明卓
13 | *
14 | * 项目: 基于用户兴趣标签的新闻推荐系统
15 | *
16 | * 作者: 原明卓
17 | *
18 | * 版本: 1.0
19 | *
20 | * 创建日期: 16-4-25 下午5:20
21 | *
22 | * 功能描述:分类信息和来源信息,用来显示菜单使用
23 | *
24 | *
25 | * 功能更新历史:
26 | *
27 | * ==================================================
28 | */
29 | public class CSCustom {
30 |
31 | private List cateVos;
32 | private List sourceVos;
33 |
34 | public List getCateVos() {
35 | return cateVos;
36 | }
37 |
38 | public void setCateVos(List cateVos) {
39 | this.cateVos = cateVos;
40 | }
41 |
42 | public List getSourceVos() {
43 | return sourceVos;
44 | }
45 |
46 | public void setSourceVos(List sourceVos) {
47 | this.sourceVos = sourceVos;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/basevo/CommentJo.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.basevo;
2 | import cn.edu.hpu.yuan.yuannews.main.data.model.base.Comment;
3 |
4 | /**
5 | * ==================================================
6 | *
7 | * 版权: 软件工程.net12-1 原明卓
8 | *
9 | * 项目: 基于用户兴趣标签的新闻推荐系统
10 | *
11 | * 作者: 原明卓
12 | *
13 | * 版本: 1.0
14 | *
15 | * 创建日期: 16-5-2 下午8:40
16 | *
17 | * 功能描述:用户端新闻评论的实体对象
18 | *
19 | *
20 | * 功能更新历史:
21 | *
22 | * ==================================================
23 | */
24 | public class CommentJo extends Comment {
25 |
26 | private Integer uid;
27 | private String nick;//昵称
28 | private String head;//头像
29 |
30 | public Integer getUid() {
31 | return uid;
32 | }
33 |
34 | public void setUid(Integer uid) {
35 | this.uid = uid;
36 | }
37 |
38 | public String getNick() {
39 | return nick;
40 | }
41 |
42 | public void setNick(String nick) {
43 | this.nick = nick;
44 | }
45 |
46 | public String getHead() {
47 | return head;
48 | }
49 |
50 | public void setHead(String head) {
51 | this.head = head;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/comment/CommentModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.comment;
2 |
3 | import android.content.Context;
4 |
5 | import cn.edu.hpu.yuan.yuannews.news.comment.adapter.CommentRecyclerAdapter;
6 | import dagger.Module;
7 | import dagger.Provides;
8 |
9 | /**
10 | * Created by yuan on 16-5-13.
11 | */
12 |
13 | @Module
14 | public class CommentModule {
15 |
16 |
17 | public CommentModule(){}
18 |
19 | private CommenContancts.CommenContanctsView commenContanctsView;
20 | private Context context;
21 |
22 | public CommentModule(CommenContancts.CommenContanctsView commenContanctsView,Context context) {
23 | this.commenContanctsView = commenContanctsView;
24 | this.context=context;
25 | }
26 |
27 |
28 | @Provides
29 | CommentFragment provideCommentFragment(){
30 | return new CommentFragment();
31 | }
32 |
33 | @Provides
34 | CommenContancts.CommenContanctsPresenter provideCommenContanctsPresenter(){
35 | return new CommemPresenter(commenContanctsView);
36 | }
37 |
38 | @Provides
39 | CommentRecyclerAdapter provideCommentRecyclerAdapter(){
40 | return new CommentRecyclerAdapter(context);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
19 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/tuijian/TuijianModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.tuijian;
2 |
3 | import android.content.Context;
4 |
5 | import cn.edu.hpu.yuan.yuannews.news.newslist.adapter.CustomRecyclerViewAdapter;
6 | import dagger.Module;
7 | import dagger.Provides;
8 |
9 | /**
10 | * Created by yuan on 16-5-13.
11 | */
12 | @Module
13 | public class TuijianModule {
14 |
15 |
16 | public TuijianModule(){}
17 |
18 | private TuijianContancts.TuijianContanctsView tuijianContanctsView;
19 | private Context context;
20 |
21 | public TuijianModule(TuijianContancts.TuijianContanctsView tuijianContanctsView,Context context) {
22 | this.context=context;
23 | this.tuijianContanctsView = tuijianContanctsView;
24 | }
25 |
26 | @Provides
27 | TuijianFragment provideTuijianFragment(){
28 | return new TuijianFragment();
29 | }
30 |
31 | @Provides
32 | TuijianContancts.TuijianContanctsPresenter provideTuijianContanctsPresenter(){
33 | return new TuijianPresenter(tuijianContanctsView);
34 | }
35 |
36 | @Provides
37 | CustomRecyclerViewAdapter provideCustomRecyclerViewAdapter(){
38 | return new CustomRecyclerViewAdapter(context);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/labels/LabelsModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.labels;
2 |
3 | import android.content.Context;
4 |
5 | import cn.edu.hpu.yuan.yuannews.news.labels.adapter.LabelsAdapter;
6 | import cn.edu.hpu.yuan.yuannews.user.label.adapter.LabelIfoAdapter;
7 | import dagger.Module;
8 | import dagger.Provides;
9 |
10 | /**
11 | * Created by yuan on 16-5-13.
12 | */
13 | @Module
14 | public class LabelsModule {
15 |
16 |
17 | public LabelsModule(){}
18 |
19 | private LabelsContancts.LabelsContanctsView labelsContanctsView;
20 | private Context context;
21 |
22 | public LabelsModule(LabelsContancts.LabelsContanctsView labelsContanctsView, Context context) {
23 | this.labelsContanctsView = labelsContanctsView;
24 | this.context=context;
25 | }
26 |
27 | @Provides
28 | LabelsFragment provideLabelsFragment(){
29 | return new LabelsFragment();
30 | }
31 |
32 | @Provides
33 | LabelsContancts.LabelsContanctsPresenter provideLabelsContanctsPresenter(){
34 | return new LabelsPresenter(labelsContanctsView);
35 | }
36 |
37 | @Provides
38 | LabelsAdapter provideLabelsIfoAdapter(){
39 | return new LabelsAdapter(context);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
23 |
24 |
--------------------------------------------------------------------------------
/yuancore/src/main/java/cn/edu/hpu/yuan/yuancore/util/DisplayUtil.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuancore.util;
2 |
3 | import android.content.Context;
4 | import android.graphics.Point;
5 | import android.view.WindowManager;
6 |
7 | /**
8 | * 作者 : andy
9 | * 日期 : 15/11/8 20:42
10 | * 邮箱 : andyxialm@gmail.com
11 | * 描述 : 换算工具类
12 | */
13 | public class DisplayUtil {
14 |
15 | /**
16 | * 根据分辨率从 dp 的单位 转成为 px(像素)
17 | */
18 | public static int dp2px(Context context, float dpValue) {
19 | final float scale = context.getResources().getDisplayMetrics().density;
20 | return (int) (dpValue * scale + 0.5f);
21 | }
22 |
23 | /**
24 | * 根据分辨率从 px(像素) 的单位 转成为 dp
25 | */
26 | public static int px2dp(Context context, float pxValue) {
27 | final float scale = context.getResources().getDisplayMetrics().density;
28 | return (int) (pxValue / scale + 0.5f);
29 | }
30 |
31 | /**
32 | * 获得屏幕尺寸
33 | * @param context
34 | * @return
35 | */
36 | public static Point getScreenSize(Context context) {
37 | Point point = new Point();
38 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
39 | wm.getDefaultDisplay().getSize(point);
40 | return point;
41 | }
42 | }
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/newslist/NewsActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.newslist;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.v7.widget.Toolbar;
6 | import android.view.View;
7 |
8 | import javax.inject.Inject;
9 |
10 | import cn.edu.hpu.yuan.yuannews.main.base.BaseActivity;
11 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
12 |
13 |
14 | /**
15 | * Created by yuan on 16-5-9.
16 | * 新闻列表Activity
17 | */
18 | public class NewsActivity extends BaseActivity {
19 |
20 |
21 |
22 | @Inject
23 | protected NewsFragment fragment;
24 |
25 | @Override
26 | protected void initView(Bundle savedInstanceState,Toolbar toolbar) {
27 | toolbar.setVisibility(View.GONE);
28 | }
29 |
30 | @Override
31 | protected BaseFragment initFragment() {
32 | return new NewsFragment();
33 | }
34 |
35 | @Override
36 | protected void setComponent() {
37 |
38 | DaggerNewsComponent.builder()
39 | .newsModule(new NewsModule())
40 | .build()
41 | .injectNewsActivity(this);
42 | }
43 |
44 | @Override
45 | protected Context getChildContext() {
46 | return NewsActivity.this;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/other/WelcomeActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.other;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.Window;
8 | import android.view.WindowManager;
9 |
10 | import cn.edu.hpu.yuan.yuannews.R;
11 | import cn.edu.hpu.yuan.yuannews.news.main.MainActivity;
12 |
13 | /**
14 | * Created by yuan on 16-5-13.
15 | * 欢迎页面
16 | */
17 | public class WelcomeActivity extends AppCompatActivity{
18 |
19 |
20 | Handler handler= new Handler();
21 |
22 | @Override
23 | public void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
26 | this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
27 | setContentView(R.layout.wlecome_activity);
28 | handler.postDelayed(new Runnable() {
29 | @Override
30 | public void run() {
31 | startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
32 | finish();
33 | }
34 | },3000);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/normal_base_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
22 |
23 |
24 |
29 |
30 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/navigation_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
20 |
21 |
31 |
32 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/base/Liked.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.base;
2 |
3 |
4 | /**
5 | * Created by yuan on 16-4-3.
6 | */
7 | public class Liked {
8 | private int id;
9 | private int status;
10 |
11 | public int getId() {
12 | return id;
13 | }
14 |
15 | public void setId(int id) {
16 | this.id = id;
17 | }
18 |
19 | public int getStatus() {
20 | return status;
21 | }
22 |
23 | public void setStatus(int status) {
24 | this.status = status;
25 | }
26 |
27 | @Override
28 | public boolean equals(Object o) {
29 | if (this == o) return true;
30 | if (o == null || getClass() != o.getClass()) return false;
31 |
32 | Liked liked = (Liked) o;
33 |
34 | if (id != liked.id) return false;
35 | if (status != liked.status) return false;
36 |
37 | return true;
38 | }
39 |
40 | @Override
41 | public int hashCode() {
42 | int result = id;
43 | result = 31 * result + status;
44 | return result;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "Liked{" +
50 | "id=" + id +
51 | ", status=" + status +
52 | '}';
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/center/CenterModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.center;
2 |
3 | import android.view.ViewGroup;
4 | import android.widget.LinearLayout;
5 |
6 | import dagger.Module;
7 | import dagger.Provides;
8 | import retrofit2.http.POST;
9 |
10 | /**
11 | * Created by yuan on 16-5-12.
12 | */
13 | @Module
14 | public class CenterModule {
15 |
16 |
17 | public CenterModule(){}
18 |
19 | private CenterContancts.CenterContanctsView centerContanctsView;
20 |
21 | public CenterModule(CenterContancts.CenterContanctsView centerContanctsView) {
22 | this.centerContanctsView = centerContanctsView;
23 | }
24 |
25 |
26 | @Provides
27 | CenterFragment provideCenterFragment(){
28 | return new CenterFragment();
29 | }
30 |
31 |
32 | @Provides
33 | CenterContancts.CenterContanctsPresenter provideCenterPersenter(){
34 | return new CenterPersenter(centerContanctsView);
35 | }
36 |
37 | @Provides
38 | ViewGroup.MarginLayoutParams provideLayoutParams(){
39 | ViewGroup.MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
40 | layoutParams.setMargins(10,10,0,0);
41 | return layoutParams;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/newsdetail/NewsDetailModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.newsdetail;
2 |
3 | import android.content.Context;
4 |
5 | import cn.edu.hpu.yuan.yuannews.news.newsdetail.adapter.NewsDetailGridViewAdapter;
6 | import dagger.Module;
7 | import dagger.Provides;
8 |
9 | /**
10 | * Created by yuan on 16-5-11.
11 | * 提供类:activity和fragment
12 | */
13 |
14 | @Module
15 | public class NewsDetailModule {
16 |
17 |
18 |
19 | private NewsDetailContancts.NewsDetailView newsDetailView;
20 | private Context context;
21 |
22 |
23 | public NewsDetailModule() {
24 |
25 | }
26 |
27 | public NewsDetailModule(NewsDetailContancts.NewsDetailView newsDetailView,Context context) {
28 | this.newsDetailView = newsDetailView;
29 | this.context=context;
30 | }
31 |
32 | @Provides
33 | NewsDetailFragment provideNewsDetaulFragment(){
34 | return NewsDetailFragment.getInstance();
35 | }
36 |
37 |
38 | @Provides
39 | NewsDetailContancts.NewsDetailPresenter provideNewsDetailPresenter(){
40 | return new NewsDetailPresenter(newsDetailView);
41 | }
42 |
43 | @Provides
44 | NewsDetailGridViewAdapter provideNewsDetailGridViewAdapter(){
45 | return new NewsDetailGridViewAdapter(context);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/labels_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
13 |
14 |
19 |
20 |
21 |
22 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/base/Cate.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.base;
2 |
3 | /**
4 | * Created by yuan on 16-4-1.
5 | */
6 | public class Cate {
7 | private int id;
8 | private String content;
9 |
10 | public int getId() {
11 | return id;
12 | }
13 |
14 | public void setId(int id) {
15 | this.id = id;
16 | }
17 |
18 |
19 | public String getContent() {
20 | return content;
21 | }
22 |
23 | public void setContent(String content) {
24 | this.content = content;
25 | }
26 |
27 | @Override
28 | public boolean equals(Object o) {
29 | if (this == o) return true;
30 | if (o == null || getClass() != o.getClass()) return false;
31 |
32 | Cate cate = (Cate) o;
33 |
34 | if (id != cate.id) return false;
35 | if (content != null ? !content.equals(cate.content) : cate.content != null) return false;
36 |
37 | return true;
38 | }
39 |
40 | @Override
41 | public int hashCode() {
42 | int result = id;
43 | result = 31 * result + (content != null ? content.hashCode() : 0);
44 | return result;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "Cate{" +
50 | "id=" + id +
51 | ", content='" + content + '\'' +
52 | '}';
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/about_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
14 |
15 |
21 |
22 |
30 |
31 |
38 |
39 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/base/Source.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.base;
2 |
3 |
4 | /**
5 | * Created by yuan on 16-4-1.
6 | */
7 |
8 | public class Source {
9 | private int id;
10 | private String source;
11 |
12 | public int getId() {
13 | return id;
14 | }
15 |
16 | public void setId(int id) {
17 | this.id = id;
18 | }
19 |
20 |
21 | public String getSource() {
22 | return source;
23 | }
24 |
25 | public void setSource(String source) {
26 | this.source = source;
27 | }
28 |
29 | @Override
30 | public boolean equals(Object o) {
31 | if (this == o) return true;
32 | if (o == null || getClass() != o.getClass()) return false;
33 |
34 | Source source1 = (Source) o;
35 |
36 | if (id != source1.id) return false;
37 | if (source != null ? !source.equals(source1.source) : source1.source != null) return false;
38 |
39 | return true;
40 | }
41 |
42 | @Override
43 | public int hashCode() {
44 | int result = id;
45 | result = 31 * result + (source != null ? source.hashCode() : 0);
46 | return result;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return "Source{" +
52 | "id=" + id +
53 | ", source='" + source + '\'' +
54 | '}';
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/util/LollipopUtils.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.util;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.os.Build;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.view.Window;
9 | import android.view.WindowManager;
10 |
11 | public class LollipopUtils {
12 |
13 | public static int getStatusBarHeight(Context context) {
14 | Context appContext = context.getApplicationContext();
15 | int result = 0;
16 | int resourceId =
17 | appContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
18 | if (resourceId > 0) {
19 | result = appContext.getResources().getDimensionPixelSize(resourceId);
20 | }
21 | Log.d("ScreenUtils", result + "");
22 | return result;
23 | }
24 |
25 | public static void setStatusbarColor(Activity activity, View view) {
26 |
27 | //对于Lollipop 的设备,只需要在style.xml中设置colorPrimaryDark即可
28 |
29 | //对于4.4的设备,如下设置padding即可,颜色同样在style.xml中配置
30 | Window w = activity.getWindow();
31 | if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
32 | w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
33 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
34 | int statusBarHeight = getStatusBarHeight(activity);
35 | view.setPadding(0, statusBarHeight, 0, 0);
36 | return;
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/newslist/NewsModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.newslist;
2 |
3 | import android.content.Context;
4 |
5 | import cn.edu.hpu.yuan.yuannews.news.newslist.adapter.CustomRecyclerViewAdapter;
6 | import dagger.Module;
7 | import dagger.Provides;
8 |
9 | /**
10 | * Created by yuan on 16-5-9.
11 | * 新闻modlue类
12 | */
13 | @Module
14 | public class NewsModule {
15 |
16 |
17 | private NewsContract.View newsView;
18 | public NewsModule(){}
19 |
20 | private Context context;
21 | private CustomRecyclerViewAdapter.NewsListItemClick newsListItemClick;
22 |
23 |
24 | public NewsModule(NewsContract.View newsView, Context context,CustomRecyclerViewAdapter.NewsListItemClick newsListItemClick) {
25 | this.newsView = newsView;
26 | this.context=context;
27 | this.newsListItemClick=newsListItemClick;
28 | }
29 |
30 | @Provides
31 | NewsFragment provideNewsFragment(){
32 | return new NewsFragment();
33 | }
34 |
35 | @Provides
36 | NewsContract.View provideNewsView(){
37 | return newsView;
38 | }
39 |
40 | @Provides
41 | NewsContract.Presenter provideNewsPresenter(){
42 | return new MewsPresenter(newsView);
43 | }
44 |
45 | @Provides
46 | CustomRecyclerViewAdapter provideCustomRecyclerViewAdapter(){
47 | return new CustomRecyclerViewAdapter(context,newsListItemClick);
48 | }
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/login/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.login;
2 |
3 | import android.support.v7.widget.Toolbar;
4 | import android.view.View;
5 | import javax.inject.Inject;
6 | import cn.edu.hpu.yuan.yuannews.R;
7 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
8 | import cn.edu.hpu.yuan.yuannews.main.base.NormalBaseActivity;
9 |
10 | /**
11 | * Created by yuan on 16-5-12.
12 | * 用户登陆页面
13 | */
14 | public class LoginActivity extends NormalBaseActivity {
15 |
16 | @Inject
17 | protected LoginFragment loginFragment;
18 |
19 | @Override
20 | protected void initView() {
21 | }
22 | @Override
23 | protected void setComponet() {
24 | DaggerLoginComponent
25 | .builder()
26 | .loginModule(new LoginModule())
27 | .build()
28 | .injectLoginActivity(this);
29 | }
30 |
31 | @Override
32 | protected void initToolbar(Toolbar toolbar) {
33 | setTitle("用户登陆");
34 | toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
35 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View v) {
38 | onBackPressed();
39 | }
40 | });
41 | }
42 |
43 | @Override
44 | protected BaseFragment initFragment() {
45 | return loginFragment;
46 | }
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/base/Taste.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.base;
2 |
3 |
4 | import java.io.Serializable;
5 |
6 | /**
7 | * Created by yuan on 16-4-1.
8 | */
9 | public class Taste implements Serializable{
10 | private int id;
11 | private String label;
12 |
13 |
14 | public int getId() {
15 | return id;
16 | }
17 |
18 | public void setId(int id) {
19 | this.id = id;
20 | }
21 |
22 | public String getLabel() {
23 | return label;
24 | }
25 |
26 | public void setLabel(String label) {
27 | this.label = label;
28 | }
29 |
30 | @Override
31 | public boolean equals(Object o) {
32 | if (this == o) return true;
33 | if (o == null || getClass() != o.getClass()) return false;
34 |
35 | Taste taste = (Taste) o;
36 |
37 | if (id != taste.id) return false;
38 | if (label != null ? !label.equals(taste.label) : taste.label != null) return false;
39 |
40 | return true;
41 | }
42 |
43 | @Override
44 | public int hashCode() {
45 | int result = id;
46 | result = 31 * result + (label != null ? label.hashCode() : 0);
47 | return result;
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return "Taste{" +
53 | "id=" + id +
54 | ", label='" + label + '\'' +
55 | '}';
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 新闻推荐
3 |
4 |
5 |
6 | 打开
7 | 关闭
8 |
9 |
10 | %1$d次阅读
11 | 分类:
12 | 来源:
13 |
14 |
15 | %1$d次阅读 %2$d次评论 %3$d人点赞
16 | 查看评论 %1$d
17 | 点赞 %1$d
18 |
19 | ID :
20 | 男
21 | 女
22 | 普通用户
23 | 管理员
24 | |
25 |
26 |
27 | 基于用户兴趣标签的新闻推荐系统是集新闻数据网络爬虫,新闻数据后台管理,网页版新闻展示和Android客户端新闻展示于一体的实现。整个系统运行主要实现流程分为三步:首先,网络爬虫爬取新闻数据,并对新闻数据进行去脏,去重操作,然后将新闻数据存储在Mysql数据库中。其次,实现系统后台管理,对新闻数据,用户数据,兴趣标签等进行优化操作。最后,系统后台实现的新闻推荐策略与用户兴趣标签管理,为用户实现网页版新闻信息展示和Android客户端新闻信息展示
28 |
29 | 北方有个自从出生就不认识菱角的人,在南方做官,(一次)他在酒席上吃菱角,(那个人)连角壳一起放进嘴里吃。有的人说:“吃菱角必须去掉壳再吃。”那人为了掩饰自己的缺点,(护住自己的短处),说:“我并不是不知道,连壳一起吃进去的原因,而是想要清热解毒。”问的人说:“北方也有这种东西吗?”他回答说:“前面的山后面的山,哪块地没有呢?”菱角生长在水中,却说是在土里生长的,这是因为他勉强地把不知道的当作知道的。
30 |
31 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/labels/LabelsActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.labels;
2 |
3 | import android.support.v7.widget.Toolbar;
4 | import android.view.View;
5 |
6 | import javax.inject.Inject;
7 |
8 | import cn.edu.hpu.yuan.yuannews.R;
9 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
10 | import cn.edu.hpu.yuan.yuannews.main.base.NormalBaseActivity;
11 |
12 | /**
13 | * Created by yuan on 16-5-13.
14 | * 所有标签页,分页加载实现
15 | */
16 | public class LabelsActivity extends NormalBaseActivity{
17 |
18 | @Inject
19 | protected LabelsFragment labelsFragment;
20 |
21 | @Override
22 | protected void initView() {
23 | }
24 |
25 | @Override
26 | protected void setComponet() {
27 | DaggerLabelsComponent
28 | .builder()
29 | .labelsModule(new LabelsModule())
30 | .build()
31 | .injectLabelsActivity(this);
32 | }
33 |
34 | @Override
35 | protected void initToolbar(Toolbar toolbar) {
36 | setTitle("关注兴趣标签");
37 | toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
38 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
39 | @Override
40 | public void onClick(View v) {
41 | onBackPressed();
42 | }
43 | });
44 | }
45 |
46 | @Override
47 | protected BaseFragment initFragment() {
48 | return labelsFragment;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/tuijian/TuijianActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.tuijian;
2 |
3 | import android.support.v7.widget.Toolbar;
4 | import android.view.View;
5 |
6 | import javax.inject.Inject;
7 |
8 | import cn.edu.hpu.yuan.yuannews.R;
9 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
10 | import cn.edu.hpu.yuan.yuannews.main.base.NormalBaseActivity;
11 |
12 | /**
13 | * Created by yuan on 16-5-13.
14 | */
15 | public class TuijianActivity extends NormalBaseActivity{
16 |
17 | @Inject
18 | protected TuijianFragment tuijianFragment;
19 |
20 | @Override
21 | protected void initView() {
22 |
23 | }
24 |
25 | @Override
26 | protected void setComponet() {
27 | DaggerTuijianComponent
28 | .builder()
29 | .tuijianModule(new TuijianModule())
30 | .build()
31 | .injectTuijianActivity(this);
32 | }
33 |
34 | @Override
35 | protected void initToolbar(Toolbar toolbar) {
36 | setTitle("推荐新闻");
37 | toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
38 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
39 | @Override
40 | public void onClick(View v) {
41 | onBackPressed();
42 | }
43 | });
44 | }
45 |
46 | @Override
47 | protected BaseFragment initFragment() {
48 | return tuijianFragment;
49 | }
50 |
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/register/RegisterActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.register;
2 |
3 | import android.support.v7.widget.Toolbar;
4 | import android.view.View;
5 |
6 | import javax.inject.Inject;
7 |
8 | import cn.edu.hpu.yuan.yuannews.R;
9 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
10 | import cn.edu.hpu.yuan.yuannews.main.base.NormalBaseActivity;
11 |
12 | /**
13 | * Created by yuan on 16-5-12.
14 | */
15 | public class RegisterActivity extends NormalBaseActivity{
16 |
17 | @Inject
18 | protected RegisterFragment registerFragment;
19 |
20 | @Override
21 | protected void initView() {
22 |
23 | }
24 | @Override
25 | protected void setComponet() {
26 |
27 | DaggerRegisterComponent
28 | .builder()
29 | .registerModule(new RegisterModule())
30 | .build()
31 | .injectRegisterActivity(this);
32 |
33 | }
34 | @Override
35 | protected void initToolbar(Toolbar toolbar) {
36 | setTitle("用户注册");
37 | toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
38 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
39 | @Override
40 | public void onClick(View v) {
41 | onBackPressed();
42 | }
43 | });
44 | }
45 |
46 | @Override
47 | protected BaseFragment initFragment() {
48 | return registerFragment;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/userIfo/UserifoActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.userIfo;
2 |
3 | import android.support.v7.widget.Toolbar;
4 | import android.view.View;
5 |
6 | import javax.inject.Inject;
7 |
8 | import cn.edu.hpu.yuan.yuannews.R;
9 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
10 | import cn.edu.hpu.yuan.yuannews.main.base.NormalBaseActivity;
11 |
12 | /**
13 | * Created by yuan on 16-5-12.
14 | */
15 | public class UserifoActivity extends NormalBaseActivity{
16 |
17 |
18 | @Inject
19 | protected UserIfoFragment userIfoFragment;
20 |
21 | @Override
22 | protected void initView() {
23 |
24 | }
25 |
26 | @Override
27 | protected void setComponet() {
28 | DaggerUserifoComponent
29 | .builder()
30 | .userIfoModule(new UserIfoModule())
31 | .build()
32 | .injectUserIfoActivity(this);
33 |
34 | }
35 |
36 | @Override
37 | protected void initToolbar(Toolbar toolbar) {
38 | setTitle("用户信息编辑");
39 | toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
40 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View v) {
43 | onBackPressed();
44 | }
45 | });
46 | }
47 |
48 | @Override
49 | protected BaseFragment initFragment() {
50 | return userIfoFragment;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/NewsAPIModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data;
2 |
3 | import android.content.Context;
4 |
5 | import cn.edu.hpu.yuan.yuannews.main.data.Local.NewsAPIShared;
6 | import cn.edu.hpu.yuan.yuannews.main.data.remote.NewsAPIService;
7 | import dagger.Module;
8 | import dagger.Provides;
9 | import retrofit2.Retrofit;
10 | import retrofit2.converter.gson.GsonConverterFactory;
11 |
12 | /**
13 | * Created by yuan on 16-5-9.
14 | * 新闻API Module, 只能在Application中进行初始化操作
15 | * 1.数据访问类 Retrofit
16 | * 2.图片访问Glide
17 | */
18 | @Module
19 | public class NewsAPIModule {
20 |
21 | protected String baseUrl;
22 |
23 | protected Retrofit retrofit;
24 |
25 | protected Context context;
26 |
27 | public NewsAPIModule(String baseUrl,Context context) {
28 | this.baseUrl = baseUrl;
29 | this.context=context;
30 | }
31 |
32 |
33 | @Provides
34 | Retrofit provideRetrofit(){
35 | retrofit = new Retrofit.Builder()
36 | .baseUrl(baseUrl)
37 | .addConverterFactory(GsonConverterFactory.create())
38 | .build();
39 | return retrofit;
40 | }
41 |
42 | @Provides
43 | NewsAPIService proviceNewsAPIService(){
44 | provideRetrofit();
45 | return retrofit.create(NewsAPIService.class);
46 | }
47 |
48 | @Provides
49 | NewsAPIShared provideNewsAPIShared(){
50 | return new NewsAPIShared(context);
51 | }
52 |
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/values-v19/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
20 |
21 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/news/NewsCustom.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.news;
2 |
3 |
4 | import cn.edu.hpu.yuan.yuannews.main.data.model.news.NewsVo;
5 |
6 | /**
7 | * ==================================================
8 | *
9 | * 版权: 软件工程.net12-1 原明卓
10 | *
11 | * 项目: 基于用户兴趣标签的新闻推荐系统
12 | *
13 | * 作者: 原明卓
14 | *
15 | * 版本: 1.0
16 | *
17 | * 创建日期: 16-4-13 下午3:53
18 | *
19 | * 功能描述: 新闻item实体类
20 | *
21 | *
22 | * 功能更新历史:
23 | * 客户端:主界面新闻展示的数据 包括阅读数量,分类信息,新闻信息
24 | *
25 | * ==================================================
26 | */
27 | public class NewsCustom extends NewsVo {
28 |
29 | private Integer cnum;//评论总数
30 |
31 | private String ccont;//分类信息
32 |
33 | private Integer znum;//点赞总数
34 |
35 | private String scont;
36 |
37 | public Integer getCnum() {
38 | return cnum;
39 | }
40 |
41 | public void setCnum(Integer cnum) {
42 | this.cnum = cnum;
43 | }
44 |
45 | public String getCcont() {
46 | return ccont;
47 | }
48 |
49 | public void setCcont(String ccont) {
50 | this.ccont = ccont;
51 | }
52 |
53 | public Integer getZnum() {
54 | return znum;
55 | }
56 |
57 | public void setZnum(Integer znum) {
58 | this.znum = znum;
59 | }
60 |
61 | public String getScont() {
62 | return scont;
63 | }
64 |
65 | public void setScont(String scont) {
66 | this.scont = scont;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/main/adapter/MainViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.main.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import cn.edu.hpu.yuan.yuannews.news.newslist.NewsFragment;
11 |
12 | /**
13 | * Created by yuan on 16-5-10.
14 | * 主页的ViewPager的Adapter
15 | */
16 | public class MainViewPagerAdapter extends FragmentPagerAdapter{
17 |
18 | private final List list_fragment=new ArrayList<>();
19 | private final List list_Title=new ArrayList<>();
20 |
21 | public void initAdapter(List fragments, List listTitle){
22 | list_fragment.addAll(fragments);
23 | list_Title.addAll(listTitle);
24 | }
25 |
26 | public MainViewPagerAdapter(FragmentManager fm) {
27 | super(fm);
28 | //默认的nType=6
29 | list_fragment.add(NewsFragment.getNewsFragmentInstance("首页",6));
30 | list_Title.add("首页");
31 | }
32 |
33 | @Override
34 | public Fragment getItem(int position) {
35 | return list_fragment.get(position);
36 | }
37 |
38 | @Override
39 | public int getCount() {
40 | return list_Title.size();
41 | }
42 |
43 | //此方法用来显示tab上的名字
44 | @Override
45 | public CharSequence getPageTitle(int position) {
46 | return list_Title.get(position);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/main/MainModule.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.main;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 |
6 | import java.util.List;
7 |
8 | import javax.inject.Singleton;
9 |
10 | import cn.edu.hpu.yuan.yuannews.news.main.adapter.MainViewPagerAdapter;
11 | import dagger.Module;
12 | import dagger.Provides;
13 |
14 | /**
15 | * Created by yuan on 16-5-10.
16 | * Module包括两个功能:
17 | * 1.给MainAvtivity提供Fragment
18 | * 2.给Fragment提供其他实例化的对象
19 | * 所以存在两个构造函数;
20 | */
21 | @Module
22 | public class MainModule {
23 |
24 |
25 | private MainContract.MainView mainView;
26 | private FragmentManager fragmentManager;
27 |
28 |
29 | //Activity 实例化
30 | public MainModule() {
31 | }
32 |
33 | //fragment实例化
34 | public MainModule(MainContract.MainView mainView,FragmentManager fragmentManager) {
35 | this.mainView = mainView;
36 | this.fragmentManager=fragmentManager;
37 | }
38 |
39 | //给mainActivity 给他Fragment
40 | @Provides
41 | MainFragment provideMainFragment(){
42 | return new MainFragment();
43 | }
44 |
45 | //给mainFragment提供MainPresenter
46 | @Provides
47 | MainContract.MainPresenter provideMainPresenter(){
48 | return new MainPresenter(mainView);
49 | }
50 |
51 | //给MainFragment提供adapter
52 | @Provides
53 | MainViewPagerAdapter provideMainViewPagerAdapter(){
54 | return new MainViewPagerAdapter(fragmentManager);
55 | }
56 |
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/label/LabelActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.label;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.widget.Toolbar;
5 | import android.view.View;
6 |
7 | import javax.inject.Inject;
8 |
9 | import cn.edu.hpu.yuan.yuannews.R;
10 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
11 | import cn.edu.hpu.yuan.yuannews.main.base.NormalBaseActivity;
12 |
13 | /**
14 | * Created by yuan on 16-5-12.
15 | */
16 | public class LabelActivity extends NormalBaseActivity{
17 |
18 | @Inject
19 | protected LabelFragment labelFragment;
20 |
21 | @Override
22 | protected void initView() {
23 | }
24 | @Override
25 | protected void setComponet() {
26 | DaggerLabelComponent
27 | .builder()
28 | .labelModule(new LabelModule())
29 | .build()
30 | .injectLabelActivity(this);
31 | }
32 |
33 | @Override
34 | protected void initToolbar(Toolbar toolbar) {
35 | setTitle("兴趣标签管理");
36 | toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
37 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View v) {
40 | onBackPressed();
41 | }
42 | });
43 | }
44 |
45 |
46 | @Override
47 | protected BaseFragment initFragment() {
48 | Bundle tasteVos = getIntent().getExtras();
49 | labelFragment.setArguments(tasteVos);
50 | return labelFragment;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/newsdetail/NewsDetailActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.newsdetail;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.v7.widget.Toolbar;
6 |
7 | import javax.inject.Inject;
8 |
9 | import cn.edu.hpu.yuan.yuancore.util.LogUtil;
10 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
11 | import cn.edu.hpu.yuan.yuannews.main.base.NormalBackActivity;
12 |
13 | /**
14 | * Created by yuan on 16-5-11.
15 | * 新闻详情页Activity
16 | */
17 | public class NewsDetailActivity extends NormalBackActivity{
18 |
19 |
20 |
21 | private static final String NEWSDETAIL_FRAGMENT_NID_KEY="news_detail_nid_key";
22 |
23 | @Inject
24 | protected NewsDetailFragment newsDetailFragment;
25 |
26 | @Override
27 | protected void initView(Bundle savedInstanceState, Toolbar toolbar) {
28 | }
29 |
30 | @Override
31 | protected BaseFragment initFragment() {
32 | Bundle bundle=new Bundle();
33 | bundle.putInt(NEWSDETAIL_FRAGMENT_NID_KEY,getIntent().getIntExtra("nid",400));
34 | newsDetailFragment.setArguments(bundle);
35 | return newsDetailFragment;
36 | }
37 |
38 | @Override
39 | protected void setComponent() {
40 | DaggerNewsDetailComponent
41 | .builder()
42 | .newsDetailModule(new NewsDetailModule())
43 | .build()
44 | .injectNewsDetailActivity(this);
45 | }
46 |
47 |
48 | @Override
49 | protected Context getChildContext() {
50 | return NewsDetailActivity.this;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/comment/CommenActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.comment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.widget.Toolbar;
5 | import android.view.View;
6 |
7 | import javax.inject.Inject;
8 |
9 | import cn.edu.hpu.yuan.yuannews.R;
10 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
11 | import cn.edu.hpu.yuan.yuannews.main.base.NormalBaseActivity;
12 |
13 | /**
14 | * Created by yuan on 16-5-13.
15 | */
16 | public class CommenActivity extends NormalBaseActivity{
17 |
18 | @Inject
19 | protected CommentFragment commentFragment;
20 |
21 | @Override
22 | protected void initView() {
23 |
24 | }
25 |
26 | @Override
27 | protected void setComponet() {
28 | DaggerCommentComponent
29 | .builder()
30 | .commentModule(new CommentModule())
31 | .build()
32 | .injectCommentActivity(this);
33 | }
34 |
35 | @Override
36 | protected void initToolbar(Toolbar toolbar) {
37 | setTitle("新闻评论列表");
38 | toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
39 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View v) {
42 | onBackPressed();
43 | }
44 | });
45 | }
46 |
47 | @Override
48 | protected BaseFragment initFragment() {
49 | Bundle bundle=new Bundle();
50 | bundle.putInt("nid",getIntent().getIntExtra("nid",0));
51 | commentFragment.setArguments(bundle);
52 | return commentFragment;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # YuanNewsForAndroid
2 | 新闻推荐系统-Android客户端
3 | * 历史遗留 - 用户没有推荐兴趣,关注标签后,推荐的新闻没有生成(服务端和客户端联合测试)
4 | * 没有兴趣标签的解决方案是什么?
5 |
6 |
7 |
8 | # 2016.05.18
9 | * 换图标,浅灰色底,绿色图标显示实现
10 | * 注册成功的提示信息(后台,在进行添加标签的时候,也需要进行新闻推荐)
11 | * RecyclerView 判断没有数据的时候,提醒没有更多数据,不能太频繁;(思路: 有数据,设置为true;没数据设置为false)
12 |
13 |
14 | # 2016.05.14
15 | * 已实现新闻推荐列表(见历史遗留)
16 | * 剩下两个内容:1.伪推送:推荐新闻通知实现;2.用户修改信息实现;
17 |
18 | # 2016.05.13
19 | * 接口:1.获取当前新闻当前用户的新闻状态,2.分页查询所有的新闻标签
20 | * 优先:1.接口实现 2.新闻详情跑通(评论及点赞)3.新闻推荐 4.信息修改 5.引导页,启动页,关于页
21 | * 优化
22 |
23 | # 2016.05.12
24 | * 用户登陆 :账户/密码
25 | * 用户注册 :账户/密码/昵称;
26 | * 兴趣标签管理
27 | * 新闻推荐实现
28 | * 用户详情页标签布局实现:
29 | * https://github.com/lankton/android-flowlayout
30 | * 修改的字体颜色有:
31 |
32 | # 2016.05.11
33 | * 新闻列表请求,包括分类,来源等请求,浮动按钮进行排序请求
34 | * 新闻详情页实现,包括评论,点赞,详情显示
35 | * 分页加载及封装
36 |
37 | # 2016.05.10
38 | * 新闻主界面实现
39 |
40 | # 2016.05.09
41 | * 架构基本实现
42 | * 主页,详情页布局采用开源 :
43 | * https://github.com/ksoichiro/Android-ObservableScrollView
44 |
45 | * Dialog
46 | * https://github.com/andyxialm/ColorDialog
47 | * 排序规则 : https://github.com/konifar/fab-transformation
48 |
49 | * 新闻界面实现思路:
50 | * 列表实现,head 分类和来源 ,默认显示正常情况
51 | * 默认显示正常情况:下面四种情况菜单-》推荐(需要登录),热度,评论,点赞;
52 |
53 | * 引导页
54 | * https://github.com/PaoloRotolo/AppIntro
55 | * 透明高亮指示层
56 | * https://github.com/hongyangAndroid/Highlight
57 |
58 | # 2016.05.06
59 | * Android 基本架构
60 | * dagger2 + mvp + Retrofit + data Binding
61 |
62 | # 2016.04.29
63 | * 添加 yuancore 模块
64 | * LogUtil : 日志打印类
65 | * DensityUtil : 获取屏幕的宽度等
66 | * DateUtils : 日期处理类,几分钟以前等
67 | * CrashHandler : 异常捕捉类
68 | * 添加网络 yuannet 模块
69 | * 图片请求及其封装 glide
--------------------------------------------------------------------------------
/yuancore/REDECORE.md:
--------------------------------------------------------------------------------
1 | # 1.ui/dialog
2 | 方式1:
3 | ColorDialog dialog = new ColorDialog(this);
4 | dialog.setTitle(getString(R.string.operation));
5 | dialog.setContentText(getString(R.string.content_text));
6 | dialog.setContentImage(getResources().getDrawable(R.mipmap.sample_img));
7 | dialog.setPositiveListener(getString(R.string.delete), new ColorDialog.OnPositiveListener() {
8 | @Override
9 | public void onClick(ColorDialog dialog) {
10 | Toast.makeText(MainActivity.this, dialog.getPositiveText().toString(), Toast.LENGTH_SHORT).show();
11 | }
12 | })
13 | .setNegativeListener(getString(R.string.cancel), new ColorDialog.OnNegativeListener() {
14 | @Override
15 | public void onClick(ColorDialog dialog) {
16 | Toast.makeText(MainActivity.this, dialog.getNegativeText().toString(), Toast.LENGTH_SHORT).show();
17 | dialog.dismiss();
18 | }
19 | }).show();
20 |
21 | 方式2:
22 | new PromptDialog(this).setDialogType(PromptDialog.DIALOG_TYPE_SUCCESS)
23 | .setTitleText("Success").setContentText("Your info text goes here. Loremipsum dolor sit amet, consecteturn adipisicing elit, sed do eiusmod.")
24 | .setPositiveListener("OK", new PromptDialog.OnPositiveListener() {
25 | @Override
26 | public void onClick(PromptDialog dialog) {
27 | dialog.dismiss();
28 | }
29 | }).show();
30 |
31 | 还需要进一步封装实现;
32 |
33 |
34 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/base/Comment.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.base;
2 |
3 |
4 | /**
5 | * Created by yuan on 16-4-3.
6 | */
7 | public class Comment {
8 | private int id;
9 | private String content;
10 | private int status;
11 |
12 |
13 | public int getId() {
14 | return id;
15 | }
16 |
17 | public void setId(int id) {
18 | this.id = id;
19 | }
20 |
21 | public String getContent() {
22 | return content;
23 | }
24 |
25 | public void setContent(String content) {
26 | this.content = content;
27 | }
28 |
29 | public int getStatus() {
30 | return status;
31 | }
32 |
33 | public void setStatus(int status) {
34 | this.status = status;
35 | }
36 |
37 | @Override
38 | public boolean equals(Object o) {
39 | if (this == o) return true;
40 | if (o == null || getClass() != o.getClass()) return false;
41 |
42 | Comment comment = (Comment) o;
43 |
44 | if (id != comment.id) return false;
45 | if (status != comment.status) return false;
46 | if (content != null ? !content.equals(comment.content) : comment.content != null) return false;
47 |
48 | return true;
49 | }
50 |
51 | @Override
52 | public int hashCode() {
53 | int result = id;
54 | result = 31 * result + (content != null ? content.hashCode() : 0);
55 | result = 31 * result + status;
56 | return result;
57 | }
58 |
59 | @Override
60 | public String toString() {
61 | return "Comment{" +
62 | "id=" + id +
63 | ", content='" + content + '\'' +
64 | ", status=" + status +
65 | '}';
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/center/CenterActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.center;
2 |
3 | import android.support.v7.widget.Toolbar;
4 | import android.view.View;
5 |
6 | import javax.inject.Inject;
7 |
8 | import cn.edu.hpu.yuan.yuannews.R;
9 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
10 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
11 | import cn.edu.hpu.yuan.yuannews.main.base.NormalBaseActivity;
12 |
13 | /**
14 | * Created by yuan on 16-5-12.
15 | */
16 | public class CenterActivity extends NormalBaseActivity{
17 |
18 |
19 | private final String SHRAED_MOREN_USER_IFNO="No Data";
20 |
21 | @Inject
22 | protected CenterFragment centerFragment;
23 |
24 | @Override
25 | protected void initView() {
26 |
27 | }
28 |
29 | @Override
30 | protected void setComponet() {
31 | DaggerCenterComponent.builder()
32 | .centerModule(new CenterModule())
33 | .build()
34 | .injectCenterActivity(this);
35 | }
36 |
37 | @Override
38 | protected void initToolbar(Toolbar toolbar) {
39 | String userNick = BaseApplication.newsAPIShared.getSharedUserNick();
40 | if(SHRAED_MOREN_USER_IFNO.equals(userNick)){
41 | setTitle("个人中心");
42 | }else{
43 | setTitle(userNick);
44 | }
45 | toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
46 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | onBackPressed();
50 | }
51 | });
52 | }
53 |
54 | @Override
55 | protected BaseFragment initFragment() {
56 | return centerFragment;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/register/RegisterPresenter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.register;
2 |
3 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
4 | import cn.edu.hpu.yuan.yuannews.main.data.model.DataBean;
5 | import cn.edu.hpu.yuan.yuannews.user.register.RegisterContancts.RegisterContanctsPresenter;
6 | import retrofit2.Call;
7 | import retrofit2.Callback;
8 | import retrofit2.Response;
9 |
10 | /**
11 | * Created by yuan on 16-5-12.
12 | */
13 | public class RegisterPresenter implements RegisterContanctsPresenter{
14 |
15 | private RegisterContancts.RegisterCOntanctsView registerCOntanctsView;
16 |
17 | public RegisterPresenter(RegisterContancts.RegisterCOntanctsView registerCOntanctsView) {
18 | this.registerCOntanctsView = registerCOntanctsView;
19 | }
20 |
21 | @Override
22 | public void postUserRegister(String nick, String num, String pass) {
23 | registerCOntanctsView.showDialog();
24 | BaseApplication.newsAPIService.postUserRegister(num,pass,nick).enqueue(new Callback() {
25 | @Override
26 | public void onResponse(Call call, Response response) {
27 |
28 | if(response.isSuccessful()){
29 | if(response.body().getCode()==0){
30 | registerCOntanctsView.showSuccess();
31 | }else{
32 | registerCOntanctsView.showError(response.body().getMsg());
33 | }
34 | }else {
35 | registerCOntanctsView.showError("网络不稳定");
36 | }
37 | }
38 | @Override
39 | public void onFailure(Call call, Throwable t) {
40 | registerCOntanctsView.showError("网络不稳定");
41 | }
42 | });
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/yuannews/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin:'com.neenbedankt.android-apt'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.2"
7 |
8 | dataBinding {
9 | enabled true //data binding
10 | }
11 |
12 | defaultConfig {
13 | applicationId "cn.edu.hpu.yuan.yuannews"
14 | minSdkVersion 14
15 | targetSdkVersion 23
16 | versionCode 2
17 | versionName "2.0"
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false //代码混淆关闭
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 |
28 |
29 | dependencies {
30 | compile fileTree(dir: 'libs', include: ['*.jar'])
31 | testCompile 'junit:junit:4.12'
32 | compile 'com.android.support:appcompat-v7:23.3.0'
33 | compile 'com.android.support:design:23.3.0'
34 | compile 'com.android.support:recyclerview-v7:23.3.0' //RecyclerView
35 | compile 'com.android.support:cardview-v7:23.3.0' //cardView
36 | compile 'com.balysv:material-ripple:1.0.2' //点击波纹效果
37 |
38 | //dagger2
39 | apt'com.google.dagger:dagger-compiler:2.0.2'//指定注解处理器
40 | compile'com.google.dagger:dagger:2.0.2'//dagger公用api
41 | provided'org.glassfish:javax.annotation:10.0-b28'//添加android缺失的部分javax注解
42 |
43 | //retrofit 2.0
44 | compile 'com.squareup.retrofit2:retrofit:2.0.2'
45 |
46 | //Gson
47 | compile 'com.squareup.retrofit2:converter-gson:2.0.2'
48 |
49 | //Glide 图片加载
50 | compile 'com.github.bumptech.glide:glide:3.7.0'
51 |
52 | //圆形头像
53 | compile 'de.hdodenhof:circleimageview:2.0.0'
54 |
55 | //进度条
56 | compile 'com.pnikosis:materialish-progress:1.7'
57 |
58 | //fastJson
59 | compile 'com.alibaba:fastjson:1.1.15'
60 |
61 | compile project(path: ':yuancore')
62 | }
63 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/main/MainActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.main;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.ActionBar;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.View;
9 | import android.widget.TextView;
10 |
11 | import com.bumptech.glide.Glide;
12 |
13 | import javax.inject.Inject;
14 |
15 | import cn.edu.hpu.yuan.yuancore.util.LogUtil;
16 | import cn.edu.hpu.yuan.yuannews.R;
17 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
18 | import cn.edu.hpu.yuan.yuannews.main.base.BaseActivity;
19 | import cn.edu.hpu.yuan.yuannews.main.base.BaseFragment;
20 | import cn.edu.hpu.yuan.yuannews.user.center.CenterActivity;
21 | import cn.edu.hpu.yuan.yuannews.user.login.LoginActivity;
22 | import de.hdodenhof.circleimageview.CircleImageView;
23 |
24 | /**
25 | * Created by yuan on 16-5-10.
26 | * 1.主界面
27 | * 2.功能:初始化界面,包括分类和来源
28 | */
29 | public class MainActivity extends BaseActivity{
30 |
31 |
32 |
33 | @Inject
34 | protected MainFragment mainFragment;
35 |
36 | @Override
37 | protected void initView(Bundle savedInstanceState, Toolbar toolbar) {
38 | ActionBar ab = getSupportActionBar();
39 | ab.setHomeAsUpIndicator(R.drawable.ic_menu);
40 | ab.setDisplayHomeAsUpEnabled(true);
41 | }
42 |
43 | @Override
44 | protected BaseFragment initFragment() {
45 | return mainFragment;
46 | }
47 |
48 | @Override
49 | protected void setComponent() {
50 | DaggerMainComponent.builder()
51 | .mainModule(new MainModule())
52 | .build()
53 | .injectMainActivity(this);
54 | }
55 |
56 | @Override
57 | protected Context getChildContext() {
58 | return MainActivity.this;
59 | }
60 |
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/yuannews/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/base_main_float_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
24 |
25 |
33 |
34 |
42 |
43 |
51 |
52 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/news_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
15 |
20 |
21 |
22 |
23 |
24 |
25 |
33 |
34 |
38 |
39 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/app/BaseApplication.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.app;
2 |
3 | import android.app.Application;
4 |
5 | import javax.inject.Inject;
6 |
7 | import cn.edu.hpu.yuan.yuancore.util.CrashHandler;
8 | import cn.edu.hpu.yuan.yuannews.main.data.Local.NewsAPIShared;
9 | import cn.edu.hpu.yuan.yuannews.main.data.NewsAPI;
10 | import cn.edu.hpu.yuan.yuannews.main.data.NewsAPIModule;
11 | import cn.edu.hpu.yuan.yuannews.main.data.remote.NewsAPIService;
12 | import cn.edu.hpu.yuan.yuannews.main.util.NotificationUtil;
13 | import retrofit2.Retrofit;
14 |
15 | /**
16 | * Created by yuan on 16-5-9.
17 | * BaseApplication
18 | * 1.初始化CrashHandler
19 | * 2.
20 | */
21 | public class BaseApplication extends Application{
22 |
23 |
24 | @Inject
25 | protected CrashHandler crashHandler;
26 | //Application的注入器
27 | private ApplicationComponent applicationComponent;
28 |
29 | @Inject
30 | public static NewsAPIService newsAPIService;
31 |
32 | @Inject
33 | public static Retrofit retrofit;
34 |
35 | @Inject
36 | public static NewsAPIShared newsAPIShared;
37 |
38 | @Inject
39 | public static NotificationUtil notificationUtil;
40 |
41 | @Override
42 | public void onCreate() {
43 | super.onCreate();
44 | applicationComponent = DaggerApplicationComponent.builder()
45 | .applicationModule(new ApplicationModule(getApplicationContext()))
46 | .newsAPIModule(new NewsAPIModule(NewsAPI.BASE_URL,this))
47 | .build();
48 | applicationComponent.injectBaseApplication(this);
49 |
50 | //初始化crashHandler
51 | crashHandler.init(getApplicationContext());
52 | }
53 |
54 | public ApplicationComponent getApplicationComponent(){
55 | return applicationComponent;
56 | }
57 |
58 | public NewsAPIService getNewsAPIService(){
59 | return newsAPIService;
60 | }
61 |
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/yuancore/src/main/java/cn/edu/hpu/yuan/yuancore/ui/dialog/AnimationLoader.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuancore.ui.dialog;
2 |
3 | import android.content.Context;
4 | import android.view.animation.AlphaAnimation;
5 | import android.view.animation.Animation;
6 | import android.view.animation.AnimationSet;
7 | import android.view.animation.ScaleAnimation;
8 |
9 |
10 | public class AnimationLoader {
11 | public static AnimationSet getInAnimation(Context context) {
12 | AnimationSet in = new AnimationSet(context, null);
13 |
14 | AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f);
15 | alpha.setDuration(90);
16 |
17 | ScaleAnimation scale1 = new ScaleAnimation(0.8f, 1.05f, 0.8f, 1.05f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
18 | scale1.setDuration(135);
19 |
20 | ScaleAnimation scale2 = new ScaleAnimation(1.05f, 0.95f, 1.05f, 0.95f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
21 | scale2.setDuration(105);
22 | scale2.setStartOffset(135);
23 |
24 | ScaleAnimation scale3 = new ScaleAnimation(0.95f, 1f, 0.95f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
25 | scale3.setDuration(60);
26 | scale3.setStartOffset(240);
27 |
28 | in.addAnimation(alpha);
29 | in.addAnimation(scale1);
30 | in.addAnimation(scale2);
31 | in.addAnimation(scale3);
32 |
33 | return in;
34 | }
35 |
36 | public static AnimationSet getOutAnimation(Context context) {
37 | AnimationSet out = new AnimationSet(context, null);
38 | AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
39 | alpha.setDuration(150);
40 | ScaleAnimation scale = new ScaleAnimation(1.0f, 0.6f, 1.0f, 0.6f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
41 | scale.setDuration(150);
42 | out.addAnimation(alpha);
43 | out.addAnimation(scale);
44 | return out;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/comments_fragment_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
13 |
20 |
21 |
28 |
29 |
37 |
38 |
45 |
46 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/base/NormalBaseActivity.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.base;
2 |
3 | import android.os.Bundle;
4 | import android.os.PersistableBundle;
5 | import android.support.v4.app.FragmentManager;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.WindowManager;
9 |
10 | import cn.edu.hpu.yuan.yuannews.R;
11 | import cn.edu.hpu.yuan.yuannews.main.app.ApplicationComponent;
12 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
13 | import cn.edu.hpu.yuan.yuannews.main.util.LollipopUtils;
14 |
15 | /**
16 | * Created by yuan on 16-5-12.
17 | *
18 | * 正常的,独立的Activity
19 | * 独立于BaseActivity :
20 | * 登陆
21 | * 注册
22 | * 个人中心
23 | * 标签管理
24 | * 关于
25 | * 这几个界面
26 | */
27 | public abstract class NormalBaseActivity extends AppCompatActivity {
28 |
29 |
30 | public ApplicationComponent getApplicationComponent() {
31 | return ((BaseApplication) getApplication()).getApplicationComponent();
32 | }
33 |
34 | Toolbar toolbar;
35 |
36 | @Override
37 | public void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.normal_base_main);
40 | setComponet();
41 | //初始化toolbar
42 | toolbar = (Toolbar) findViewById(R.id.toolbar);
43 | setSupportActionBar(toolbar);
44 | // LollipopUtils.setStatusbarColor(this, toolbar);
45 |
46 | //初始化fragment
47 | BaseFragment fragment = initFragment();
48 | fragment.setApplicationComponent(getApplicationComponent());
49 | FragmentManager manager = getSupportFragmentManager();
50 | manager.beginTransaction().replace(R.id.contentFrame, fragment).commit();
51 | //初始化toolbar
52 | initToolbar(toolbar);
53 |
54 | initView();
55 |
56 | }
57 |
58 | protected abstract void initView();
59 |
60 | protected abstract void setComponet();
61 |
62 | protected abstract void initToolbar(Toolbar toolbar);
63 |
64 | protected abstract BaseFragment initFragment();
65 | }
66 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/newsdetail/adapter/NewsDetailGridViewAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.newsdetail.adapter;
2 |
3 | import android.content.Context;
4 | import android.databinding.DataBindingUtil;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.BaseAdapter;
9 | import com.bumptech.glide.Glide;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import cn.edu.hpu.yuan.yuannews.R;
13 | import cn.edu.hpu.yuan.yuannews.databinding.NewsDetailFragmentGridItemBinding;
14 | import cn.edu.hpu.yuan.yuannews.main.data.NewsAPI;
15 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.LikedVo;
16 |
17 | /**
18 | * Created by yuan on 16-5-12.
19 | */
20 | public class NewsDetailGridViewAdapter extends BaseAdapter{
21 |
22 | private final List likedVos=new ArrayList<>();
23 |
24 | public void initData(List Vos){
25 | likedVos.addAll(Vos);
26 | }
27 |
28 | public void clearData(){
29 | likedVos.clear();
30 | }
31 |
32 | private Context context;
33 |
34 | private LayoutInflater inflater;
35 |
36 | public NewsDetailGridViewAdapter(Context context) {
37 | this.context = context;
38 | inflater=LayoutInflater.from(context);
39 |
40 | }
41 |
42 | @Override
43 | public int getCount() {
44 | return likedVos.size();
45 | }
46 |
47 | @Override
48 | public Object getItem(int position) {
49 | return likedVos.get(position);
50 | }
51 |
52 | @Override
53 | public long getItemId(int position) {
54 | return position;
55 | }
56 |
57 | @Override
58 | public View getView(int position, View convertView, ViewGroup parent) {
59 | NewsDetailFragmentGridItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.news_detail_fragment_grid_item, parent, false);
60 | String url=NewsAPI.BASE_IMAGE_URL+likedVos.get(position).getHead();
61 | Glide.with(context)
62 | .load(url)
63 | .error(R.mipmap.loaderror)
64 | .placeholder(R.mipmap.loading)
65 | .into(binding.profileImage);
66 | return binding.getRoot();
67 | }
68 |
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/Local/NewsAPIShared.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.Local;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 |
7 | /**
8 | * Created by yuan on 16-5-12.
9 | * SharedPresence 本地持久化,用户数据
10 | */
11 | public class NewsAPIShared {
12 |
13 | private final String SHARED_PREFERENCES_NAME="yuannews";
14 | private final String SHRAED_USER_IFO_HEAD_KEY="shared_user_ifo_head_key";
15 | private final String SHRAED_USER_IFO_NICK_KEY="shared_user_ifo_nick_key";
16 | private final String SHRAED_USER_ID_KEY="shared_user_id_key";
17 | private final String SHRAED_MOREN_USER_IFNO="No Data";
18 | private final String SHARED_NOTIFICATION_COUNT="shared_notification_count";
19 |
20 | private SharedPreferences sharedPreferences;
21 | private SharedPreferences.Editor editor;
22 |
23 |
24 | public NewsAPIShared(Context context) {
25 | sharedPreferences=context.getSharedPreferences(SHARED_PREFERENCES_NAME,Context.MODE_PRIVATE);
26 | editor=sharedPreferences.edit();
27 | }
28 |
29 | /**
30 | * =====================================
31 | * 用户信息
32 | */
33 | public void putSharedUserIfo(String headUrl,Integer uid,String nick){
34 | editor.putString(SHRAED_USER_IFO_HEAD_KEY,headUrl);
35 | editor.putInt(SHRAED_USER_ID_KEY,uid);
36 | editor.putString(SHRAED_USER_IFO_NICK_KEY,nick);
37 | editor.commit();
38 | }
39 |
40 | public String getSharedUserHead(){
41 | return sharedPreferences.getString(SHRAED_USER_IFO_HEAD_KEY,SHRAED_MOREN_USER_IFNO);
42 | }
43 |
44 | public String getSharedUserNick(){
45 | return sharedPreferences.getString(SHRAED_USER_IFO_NICK_KEY,SHRAED_MOREN_USER_IFNO);
46 | }
47 |
48 | public Integer getSharedUserID(){
49 | return sharedPreferences.getInt(SHRAED_USER_ID_KEY,0);
50 | }
51 |
52 |
53 | /**
54 | * ========================================
55 | * 通知的新闻总数
56 | */
57 | public Integer getSharedNotificationCount(){
58 | return sharedPreferences.getInt(SHARED_NOTIFICATION_COUNT,0);
59 | }
60 |
61 | public void putSharedNotificationCount(Integer count){
62 | editor.putInt(SHARED_NOTIFICATION_COUNT,count);
63 | editor.commit();
64 | }
65 |
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/label_fragment_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
15 |
16 |
25 |
26 |
41 |
42 |
56 |
57 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/login/LoginPresenter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.login;
2 |
3 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
4 | import cn.edu.hpu.yuan.yuannews.main.data.NewsAPI;
5 | import cn.edu.hpu.yuan.yuannews.main.data.model.DataBean;
6 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.UserVo;
7 | import retrofit2.Call;
8 | import retrofit2.Callback;
9 | import retrofit2.Response;
10 |
11 | /**
12 | * Created by yuan on 16-5-12.
13 | */
14 | public class LoginPresenter implements LoginContract.LoginContractPresenter{
15 |
16 |
17 | private LoginContract.LoginContractView loginContractView;
18 |
19 | public LoginPresenter(LoginContract.LoginContractView loginContractView) {
20 | this.loginContractView = loginContractView;
21 | }
22 |
23 | @Override
24 | public void postUserLogin(String num, String pass) {
25 | loginContractView.showDialog();
26 | BaseApplication.newsAPIService.postUserLogin(num,pass).enqueue(new Callback>() {
27 | @Override
28 | public void onResponse(Call> call, Response> response) {
29 | loginContractView.dmissDialog();
30 | if(response.isSuccessful()){
31 | DataBean body = response.body();
32 | if(body.getCode()==0){
33 |
34 | UserVo data = body.getData();
35 | if(data!=null){
36 | //存储用户信息
37 | BaseApplication.newsAPIShared.putSharedUserIfo(NewsAPI.BASE_IMAGE_URL+data.getHead()
38 | ,data.getId(),
39 | data.getNick());
40 | loginContractView.success();
41 | }else{
42 | loginContractView.error("请求失败");
43 | }
44 | }else {
45 | loginContractView.error(body.getMsg());
46 | }
47 | }else {
48 | loginContractView.error("网络错误");
49 | }
50 | }
51 | @Override
52 | public void onFailure(Call> call, Throwable t) {
53 | loginContractView.error("网络错误");
54 | }
55 | });
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/label_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
16 |
17 |
23 |
24 |
29 |
30 |
35 |
36 |
40 |
41 |
49 |
50 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/comment/adapter/CommentRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.comment.adapter;
2 |
3 | import android.content.Context;
4 | import android.databinding.DataBindingUtil;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.bumptech.glide.Glide;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | import cn.edu.hpu.yuan.yuannews.R;
16 | import cn.edu.hpu.yuan.yuannews.databinding.CommentsFragmentItemBinding;
17 | import cn.edu.hpu.yuan.yuannews.main.data.NewsAPI;
18 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.CommentJo;
19 |
20 |
21 | /**
22 | * Created by yuan on 16-5-13.
23 | * 在create的时候通过 tag 传递binding
24 | */
25 | public class CommentRecyclerAdapter extends RecyclerView.Adapter{
26 |
27 |
28 | private List commentJos=new ArrayList<>();
29 |
30 | public void addComemntJo(ArrayList commentss){
31 | commentJos.addAll(commentss);
32 | }
33 |
34 | public void clearComemntJos(){
35 | commentJos.clear();
36 | }
37 |
38 | private LayoutInflater inflater;
39 | private Context context;
40 |
41 | public CommentRecyclerAdapter(Context context) {
42 | this.inflater = LayoutInflater.from(context);
43 | this.context=context;
44 | }
45 |
46 | @Override
47 | public CommentViewAdapter onCreateViewHolder(ViewGroup parent, int viewType) {
48 | CommentsFragmentItemBinding binding= DataBindingUtil.inflate(inflater, R.layout.comments_fragment_item,parent,false);
49 | return new CommentViewAdapter(binding.getRoot());
50 | }
51 |
52 | @Override
53 | public void onBindViewHolder(CommentViewAdapter holder, int position) {
54 | CommentsFragmentItemBinding binding=DataBindingUtil.bind(holder.itemView);
55 | CommentJo commentJo = commentJos.get(position);
56 | binding.setCommentJo(commentJo);
57 | Glide.with(context)
58 | .load(NewsAPI.BASE_IMAGE_URL+commentJo.getHead())
59 | .error(R.mipmap.ic_news)
60 | .placeholder(R.mipmap.user_head)
61 | .into(binding.profileImage);
62 | }
63 |
64 | @Override
65 | public int getItemCount() {
66 | return commentJos.size();
67 | }
68 |
69 | class CommentViewAdapter extends RecyclerView.ViewHolder{
70 | public CommentViewAdapter(View itemView) {
71 | super(itemView);
72 | }
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/tuijian/TuijianPresenter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.tuijian;
2 |
3 | import java.util.ArrayList;
4 |
5 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
6 | import cn.edu.hpu.yuan.yuannews.main.data.model.DataBean;
7 | import cn.edu.hpu.yuan.yuannews.main.data.model.news.NewsCustom;
8 | import retrofit2.Call;
9 | import retrofit2.Callback;
10 | import retrofit2.Response;
11 |
12 | /**
13 | * Created by yuan on 16-5-13.
14 | */
15 | public class TuijianPresenter implements TuijianContancts.TuijianContanctsPresenter{
16 |
17 |
18 | private TuijianContancts.TuijianContanctsView tuijianContanctsView;
19 |
20 | public TuijianPresenter(TuijianContancts.TuijianContanctsView tuijianContanctsView) {
21 | this.tuijianContanctsView = tuijianContanctsView;
22 | }
23 |
24 | private int p=1;
25 |
26 | private void getTuijianData(int p,int type){
27 | tuijianContanctsView.showDialog();
28 | int uid = BaseApplication.newsAPIShared.getSharedUserID();
29 | BaseApplication.newsAPIService.getTuijianNews(uid,20,type,p).enqueue(new Callback>>() {
30 | @Override
31 | public void onResponse(Call>> call, Response>> response) {
32 |
33 | if(response.isSuccessful()){
34 | DataBean> body = response.body();
35 | if(body.getCode()==0){
36 | ArrayList data = body.getData();
37 | if(data.size()==0){
38 | tuijianContanctsView.showNoData();
39 | }else{
40 | tuijianContanctsView.showNewsData(data);
41 | }
42 |
43 | }else{
44 | tuijianContanctsView.showErrorMsg(body.getMsg());
45 | }
46 |
47 | }else{
48 | tuijianContanctsView.showErrorMsg("网络不稳定");
49 | }
50 |
51 | }
52 |
53 | @Override
54 | public void onFailure(Call>> call, Throwable t) {
55 | tuijianContanctsView.showErrorMsg("网络不稳定");
56 | }
57 | });
58 |
59 | }
60 |
61 | @Override
62 | public void initNewsListData(int type) {
63 | p=1;
64 | getTuijianData(p,type);
65 | }
66 |
67 | @Override
68 | public void nextNewsListData(int type) {
69 | p=p+1;
70 | getTuijianData(p,type);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/label/adapter/LabelIfoAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.label.adapter;
2 |
3 | import android.content.Context;
4 | import android.databinding.DataBindingUtil;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.BaseAdapter;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import cn.edu.hpu.yuan.yuannews.R;
14 | import cn.edu.hpu.yuan.yuannews.databinding.LabelFragmentItemBinding;
15 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.TasteVo;
16 |
17 | /**
18 | * Created by yuan on 16-5-12.
19 | */
20 | public class LabelIfoAdapter extends BaseAdapter{
21 |
22 | private final List tasteVos=new ArrayList<>();
23 |
24 | public void addTasteVo(List tastes){
25 | tasteVos.clear();
26 | tasteVos.addAll(tastes);
27 | }
28 |
29 | public void removeTasteVo(int position){
30 | tasteVos.remove(position);
31 | }
32 |
33 | public void addTasteVo(TasteVo tasteVo){
34 | tasteVos.add(0,tasteVo);
35 | }
36 |
37 | private LayoutInflater inflater;
38 |
39 | private OnDeleteItemClick onDeleteItemClick;
40 |
41 | public void setOnDeleteItemClick(OnDeleteItemClick onDeleteItemClick) {
42 | this.onDeleteItemClick = onDeleteItemClick;
43 | }
44 |
45 | public LabelIfoAdapter(Context context){
46 | inflater=LayoutInflater.from(context);
47 | }
48 |
49 |
50 |
51 | @Override
52 | public int getCount() {
53 | return tasteVos.size();
54 | }
55 |
56 | @Override
57 | public Object getItem(int position) {
58 | return tasteVos.get(position);
59 | }
60 |
61 | @Override
62 | public long getItemId(int position) {
63 | return position;
64 | }
65 |
66 | @Override
67 | public View getView(final int position, View convertView, ViewGroup parent) {
68 | LabelFragmentItemBinding binding= DataBindingUtil.inflate(inflater, R.layout.label_fragment_item,parent,false);
69 | convertView=binding.getRoot();
70 | final TasteVo tasteVo = tasteVos.get(position);
71 | binding.setLabel(tasteVo.getLabel());
72 | binding.num.setText((position+1)+"");
73 | binding.btnDelete.setOnClickListener(new View.OnClickListener() {
74 | @Override
75 | public void onClick(View v) {
76 | onDeleteItemClick.onDelete(tasteVo,position);
77 | }
78 | });
79 | return convertView;
80 | }
81 |
82 | public interface OnDeleteItemClick{
83 | void onDelete(TasteVo tasteVo,int position);
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.base;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.view.View;
9 | import com.pnikosis.materialishprogress.ProgressWheel;
10 | import cn.edu.hpu.yuan.yuannews.main.app.ApplicationComponent;
11 | import cn.edu.hpu.yuan.yuannews.main.data.remote.NewsAPIService;
12 |
13 | /**
14 | * Created by yuan on 16-5-9.
15 | * Fragment 基类
16 | * 1.为广大的fragment提供支持
17 | * 2.ApplicationComponent
18 | */
19 | public abstract class BaseFragment extends Fragment{
20 |
21 |
22 | protected ApplicationComponent applicationComponent;
23 | protected NewsAPIService newsAPIService;
24 | protected Activity activity;
25 |
26 | public void setApplicationComponent(ApplicationComponent applicationComponent) {
27 | this.applicationComponent = applicationComponent;
28 | }
29 |
30 | public ApplicationComponent getApplicationComponent() {
31 | return applicationComponent;
32 | }
33 |
34 | public NewsAPIService getNewsAPIService() {
35 | return newsAPIService;
36 | }
37 |
38 | public void setNewsAPIService(NewsAPIService newsAPIService) {
39 | this.newsAPIService = newsAPIService;
40 | }
41 |
42 | protected boolean isVisible;
43 | private ProgressWheel wheel;
44 |
45 |
46 | @Override
47 | public void onCreate(@Nullable Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | activity=getActivity();
50 | initComponent();
51 | }
52 |
53 | @Override
54 | public void setUserVisibleHint(boolean isVisibleToUser) {
55 | super.setUserVisibleHint(isVisibleToUser);
56 | if(getUserVisibleHint()){
57 | isVisible=true;
58 | }else{
59 | isVisible=false;
60 | }
61 | }
62 |
63 |
64 | @Override
65 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
66 | super.onViewCreated(view, savedInstanceState);
67 | initProgress();
68 | }
69 |
70 | private void initProgress() {
71 | wheel = new ProgressWheel(getContext());
72 | wheel.setBarColor(Color.GREEN);
73 | wheel.setEnabled(true);
74 | wheel.setBarColor(Color.BLUE);
75 | wheel.setBackgroundColor(Color.GRAY);
76 | }
77 |
78 | protected void showProgress(){
79 | wheel.setVisibility(View.VISIBLE);
80 | }
81 |
82 | protected void hideProgress(){
83 | wheel.setVisibility(View.GONE);
84 | }
85 |
86 | /**
87 | * 初始化变量操作(注入器注入)
88 | */
89 | protected abstract void initComponent();
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/labels/adapter/LabelsAdapter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.labels.adapter;
2 |
3 | import android.content.Context;
4 | import android.databinding.DataBindingUtil;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import cn.edu.hpu.yuan.yuannews.R;
13 | import cn.edu.hpu.yuan.yuannews.databinding.LabelFragmentItemBinding;
14 |
15 | /**
16 | * Created by yuan on 16-5-12.
17 | */
18 | public class LabelsAdapter extends RecyclerView.Adapter{
19 |
20 |
21 | private final List tasteVos=new ArrayList<>();
22 |
23 | public void initTasteVo(){
24 | tasteVos.clear();
25 | }
26 |
27 | public void addTasteVo(List tastes){
28 | tasteVos.removeAll(tastes);//移除以存在的兴趣标签
29 | tasteVos.addAll(tastes);
30 | }
31 |
32 | public void removeTasteVo(String label){
33 | tasteVos.remove(label);
34 | }
35 |
36 |
37 | private LayoutInflater inflater;
38 |
39 | private OnDeleteItemClick onDeleteItemClick;
40 |
41 | public void setOnDeleteItemClick(OnDeleteItemClick onDeleteItemClick) {
42 | this.onDeleteItemClick = onDeleteItemClick;
43 | }
44 |
45 | public LabelsAdapter(Context context){
46 | inflater=LayoutInflater.from(context);
47 | }
48 |
49 | @Override
50 | public LabelsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
51 | LabelFragmentItemBinding binding= DataBindingUtil.inflate(inflater, R.layout.label_fragment_item,parent,false);
52 | LabelsViewHolder labelsViewHolder=new LabelsViewHolder(binding.getRoot());
53 | return labelsViewHolder;
54 | }
55 |
56 | @Override
57 | public void onBindViewHolder(LabelsViewHolder holder, final int position) {
58 | final String tasteVo = tasteVos.get(position);
59 | LabelFragmentItemBinding binding=DataBindingUtil.getBinding(holder.itemView);
60 | binding.setLabel(tasteVo);
61 | binding.num.setText((position+1)+"");
62 | binding.btnDelete.setText("关注");
63 | binding.btnDelete.setOnClickListener(new View.OnClickListener() {
64 | @Override
65 | public void onClick(View v) {
66 | onDeleteItemClick.onDelete(tasteVo,position);
67 | }
68 | });
69 | }
70 |
71 | @Override
72 | public int getItemCount() {
73 | return tasteVos.size();
74 | }
75 |
76 | class LabelsViewHolder extends RecyclerView.ViewHolder{
77 |
78 | public LabelsViewHolder(View itemView) {
79 | super(itemView);
80 | }
81 | }
82 |
83 |
84 | public interface OnDeleteItemClick{
85 | void onDelete(String tasteVo, int position);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/base/News.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.base;
2 |
3 |
4 | /**
5 | * Created by yuan on 16-4-1.
6 | */
7 | public class News {
8 | private int id;
9 | private String title;
10 | private String content;
11 | private String dt;
12 | private String img;
13 | private int rnum;
14 |
15 |
16 | public int getId() {
17 | return id;
18 | }
19 |
20 | public void setId(int id) {
21 | this.id = id;
22 | }
23 |
24 | public String getTitle() {
25 | return title;
26 | }
27 |
28 | public void setTitle(String title) {
29 | this.title = title;
30 | }
31 |
32 | public String getContent() {
33 | return content;
34 | }
35 |
36 | public void setContent(String content) {
37 | this.content = content;
38 | }
39 |
40 | public String getDt() {
41 | return dt;
42 | }
43 |
44 | public void setDt(String dt) {
45 | this.dt = dt;
46 | }
47 |
48 | public String getImg() {
49 | return img;
50 | }
51 |
52 | public void setImg(String img) {
53 | this.img = img;
54 | }
55 |
56 |
57 | public int getRnum() {
58 | return rnum;
59 | }
60 |
61 | public void setRnum(int rnum) {
62 | this.rnum = rnum;
63 | }
64 |
65 | @Override
66 | public boolean equals(Object o) {
67 | if (this == o) return true;
68 | if (o == null || getClass() != o.getClass()) return false;
69 |
70 | News news = (News) o;
71 |
72 | if (id != news.id) return false;
73 | if (rnum != news.rnum) return false;
74 | if (title != null ? !title.equals(news.title) : news.title != null) return false;
75 | if (content != null ? !content.equals(news.content) : news.content != null) return false;
76 | if (dt != null ? !dt.equals(news.dt) : news.dt != null) return false;
77 | if (img != null ? !img.equals(news.img) : news.img != null) return false;
78 |
79 | return true;
80 | }
81 |
82 | @Override
83 | public int hashCode() {
84 | int result = id;
85 | result = 31 * result + (title != null ? title.hashCode() : 0);
86 | result = 31 * result + (content != null ? content.hashCode() : 0);
87 | result = 31 * result + (dt != null ? dt.hashCode() : 0);
88 | result = 31 * result + (img != null ? img.hashCode() : 0);
89 | result = 31 * result + rnum;
90 | return result;
91 | }
92 |
93 | @Override
94 | public String toString() {
95 | return "News{" +
96 | "id=" + id +
97 | ", title='" + title + '\'' +
98 | ", content='" + content + '\'' +
99 | ", dt='" + dt + '\'' +
100 | ", img='" + img + '\'' +
101 | ", rnum=" + rnum +
102 | '}';
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/main/MainPresenter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.main;
2 |
3 | import android.support.v4.app.Fragment;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import cn.edu.hpu.yuan.yuancore.util.LogUtil;
9 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
10 | import cn.edu.hpu.yuan.yuannews.main.data.model.DataBean;
11 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.CateVo;
12 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.SourceVo;
13 | import cn.edu.hpu.yuan.yuannews.main.data.model.news.CSCustom;
14 | import cn.edu.hpu.yuan.yuannews.news.newslist.NewsFragment;
15 | import retrofit2.Call;
16 | import retrofit2.Callback;
17 | import retrofit2.Response;
18 |
19 | /**
20 | * Created by yuan on 16-5-10.
21 | * Presenter具体实现类
22 | */
23 | public class MainPresenter implements MainContract.MainPresenter{
24 |
25 |
26 | private MainContract.MainView mainView;
27 |
28 | public MainPresenter(MainContract.MainView mainView) {
29 | this.mainView = mainView;
30 | }
31 |
32 | @Override
33 | public void loadDataRequest() {
34 | //加载数据操作
35 | mainView.showLoadDialog();
36 | BaseApplication.newsAPIService.getCateSource().enqueue(new Callback>() {
37 | @Override
38 | public void onResponse(Call> call, Response> response) {
39 | mainView.finishLoadDialog();
40 | if(response.isSuccessful()){
41 | if(response.body().getCode()==0){
42 |
43 | List fragments=new ArrayList<>();
44 | List titles=new ArrayList<>();
45 |
46 | for(CateVo cateVo:response.body().getData().getCateVos()){
47 | //分类的nType=7
48 | fragments.add(NewsFragment.getNewsFragmentInstance(cateVo.getContent(),7));
49 | titles.add(cateVo.getContent());
50 | }
51 |
52 | for (SourceVo sourceVo:response.body().getData().getSourceVos()){
53 | //来源的nType=8
54 | fragments.add(NewsFragment.getNewsFragmentInstance(sourceVo.getSource(),8));
55 | titles.add(sourceVo.getSource());
56 | }
57 | LogUtil.v(titles.toString());
58 | mainView.showLoadData(fragments,titles);
59 | }else{
60 | mainView.loadMsg(response.body().getMsg());
61 | }
62 | }else{
63 | mainView.loadError();
64 | }
65 | }
66 |
67 | @Override
68 | public void onFailure(Call> call, Throwable t) {
69 | mainView.finishLoadDialog();
70 | mainView.loadError();
71 | t.printStackTrace();
72 | }
73 | });
74 | }
75 |
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/newslist/MewsPresenter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.newslist;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Map;
5 |
6 | import cn.edu.hpu.yuan.yuancore.util.LogUtil;
7 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
8 | import cn.edu.hpu.yuan.yuannews.main.data.NewsAPIMapUtil;
9 | import cn.edu.hpu.yuan.yuannews.main.data.model.DataBean;
10 | import cn.edu.hpu.yuan.yuannews.main.data.model.news.NewsCustom;
11 | import retrofit2.Call;
12 | import retrofit2.Callback;
13 | import retrofit2.Response;
14 |
15 | /**
16 | * Created by yuan on 16-5-9.
17 | * 新闻列表Presenter
18 | */
19 | public class MewsPresenter implements NewsContract.Presenter{
20 |
21 | private NewsContract.View newsPresenter;
22 |
23 | public MewsPresenter(NewsContract.View newsPresenter) {
24 | this.newsPresenter = newsPresenter;
25 | }
26 |
27 | private int p=1;
28 |
29 | private void showNewsListData(String title,int type, int nType) {
30 | newsPresenter.showDialog();
31 | Map options = NewsAPIMapUtil.getNewsListMap(title,type, p, nType);
32 | Call>> newsList = BaseApplication.newsAPIService.getNewsList(options);
33 | newsList.enqueue(new Callback>>(){
34 |
35 | @Override
36 | public void onResponse(Call>> call, Response>> response) {
37 | newsPresenter.dismssDiolog();
38 | DataBean> data = response.body();
39 | if(data!=null){
40 | LogUtil.v(" data "+data.toString());
41 | if(data.getCode()==0){
42 | if(data.getData()!=null && data.getData().size()!=0) {
43 | newsPresenter.showNewsList(data.getData());
44 | }else {
45 | newsPresenter.showNotData();
46 | }
47 | }else{
48 | newsPresenter.showSnackBar(data.getMsg());
49 | }
50 |
51 | }else{
52 | LogUtil.v(" data is null");
53 | newsPresenter.showNotData();
54 | }
55 | }
56 |
57 | @Override
58 | public void onFailure(Call>> call, Throwable t) {
59 | newsPresenter.dismssDiolog();
60 | t.printStackTrace();
61 | }
62 | });
63 |
64 | }
65 |
66 | @Override
67 | public void initNewsListData(String title, int type, int nType) {
68 | newsPresenter.showInitNewsList();
69 | p=1;
70 | showNewsListData(title,type,nType);
71 | }
72 |
73 | @Override
74 | public synchronized void nextNewsListData(String title, int type, int nType) {
75 | p+=1;
76 | showNewsListData(title,type,nType);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/yuannews/src/main/res/layout/commens_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
18 |
19 |
25 |
31 |
32 |
33 |
38 |
39 |
44 |
45 |
49 |
50 |
58 |
59 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/util/NotificationUtil.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.util;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Notification;
5 | import android.app.NotificationManager;
6 | import android.app.PendingIntent;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.os.Build;
10 |
11 | import cn.edu.hpu.yuan.yuannews.R;
12 | import cn.edu.hpu.yuan.yuannews.main.base.BaseActivity;
13 | import cn.edu.hpu.yuan.yuannews.main.data.model.news.NewsCustom;
14 | import cn.edu.hpu.yuan.yuannews.main.data.model.news.TuijianModel;
15 |
16 | /**
17 | * Created by yuan on 16-5-18.
18 | * 通知util - 实现通知的初始化,更新,删除操作;
19 | * (1)显示通知
20 | * (2)隐藏通知
21 | * (3)更新通知实现
22 | */
23 | public class NotificationUtil {
24 |
25 |
26 | private Notification.Builder builder;
27 | private static NotificationUtil notificationUtil;
28 | private final int NOTIFICATION_ID=1;
29 | private NotificationManager manager;
30 |
31 | public NotificationUtil(Context context) {
32 | builder=new Notification.Builder(context);
33 | manager= (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
34 | }
35 |
36 | public static NotificationUtil newInstance(Context c) {
37 | if(notificationUtil==null) {
38 | notificationUtil = new NotificationUtil(c);
39 | }
40 |
41 | return notificationUtil;
42 | }
43 |
44 | /**
45 | * 初始化通知
46 | */
47 | public void initNotification(){
48 | builder.setSmallIcon(R.mipmap.ic_news_no);
49 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
50 | builder.setPriority(Notification.PRIORITY_DEFAULT);
51 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
52 | builder.setCategory(Notification.CATEGORY_MESSAGE);
53 | }
54 | }
55 | }
56 |
57 | /**
58 | * 显示通知
59 | * @param model
60 | */
61 | public void showNotification(Context context,TuijianModel model){
62 |
63 | initNotification();
64 |
65 | NewsCustom newsCustom = model.getNewsCustom();
66 | String title=newsCustom.getTitle();
67 | title=title.length()>20?title.substring(0,20)+"...":title;
68 | builder.setContentText(title);
69 | builder.setContentTitle("你收到了"+model.getCount()+"条推荐新闻");
70 |
71 |
72 | Intent intent=new Intent();
73 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
74 | intent.setClass(context,BaseActivity.class);
75 |
76 | PendingIntent pendingIntent=PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_CANCEL_CURRENT);
77 |
78 | builder.setContentText(title);
79 | builder.setFullScreenIntent(pendingIntent,true);
80 | builder.setDefaults(Notification.DEFAULT_ALL);
81 |
82 | Notification build;
83 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
84 | build= builder.build();
85 | }else{
86 | build = builder.getNotification();
87 | manager.notify(NOTIFICATION_ID,build);
88 | }
89 | manager.notify(NOTIFICATION_ID,build);
90 | }
91 |
92 |
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/news/labels/LabelsPresenter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.news.labels;
2 |
3 | import java.util.List;
4 |
5 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
6 | import cn.edu.hpu.yuan.yuannews.main.data.model.DataBean;
7 | import retrofit2.Call;
8 | import retrofit2.Callback;
9 | import retrofit2.Response;
10 |
11 | /**
12 | * Created by yuan on 16-5-13.
13 | */
14 | public class LabelsPresenter implements LabelsContancts.LabelsContanctsPresenter{
15 |
16 | private LabelsContancts.LabelsContanctsView labelsContanctsView;
17 |
18 |
19 | private int uid;
20 | private int p;
21 |
22 | public LabelsPresenter(LabelsContancts.LabelsContanctsView labelsContanctsView) {
23 | this.labelsContanctsView = labelsContanctsView;
24 | uid= BaseApplication.newsAPIShared.getSharedUserID();
25 | p=0;
26 | }
27 |
28 | public void getLabelsPageData(int p) {
29 | labelsContanctsView.showDialog();
30 | uid= BaseApplication.newsAPIShared.getSharedUserID();
31 | BaseApplication.newsAPIService.getNewsTaste(uid,20,p).enqueue(new Callback>>() {
32 | @Override
33 | public void onResponse(Call>> call, Response>> response) {
34 | if(response.isSuccessful()){
35 | if(response.body().getCode()==0){
36 | labelsContanctsView.showLabelsData(response.body().getData());
37 | }else{
38 | labelsContanctsView.showErrorMsg(response.body().getMsg());
39 | }
40 | }else{
41 | labelsContanctsView.showErrorMsg("网络不稳定");
42 | }
43 | }
44 |
45 | @Override
46 | public void onFailure(Call>> call, Throwable t) {
47 | labelsContanctsView.showErrorMsg("网络不稳定");
48 | }
49 | });
50 | }
51 |
52 | @Override
53 | public void initgetTasteData() {
54 | p=1;
55 | getLabelsPageData(1);
56 |
57 | }
58 |
59 | @Override
60 | public void nextgetTasteData() {
61 | p+=1;
62 | getLabelsPageData(p);
63 | }
64 |
65 | @Override
66 | public void userAddTaste(String label) {
67 | uid= BaseApplication.newsAPIShared.getSharedUserID();
68 | BaseApplication.newsAPIService.postAddLabel(uid,label).enqueue(new Callback() {
69 | @Override
70 | public void onResponse(Call call, Response response) {
71 | if(response.isSuccessful()){
72 |
73 | if(response.body().getCode()==0){
74 | labelsContanctsView.addTasteSuccess();
75 | }else{
76 | labelsContanctsView.showErrorMsg(response.body().getMsg());
77 | }
78 |
79 | }else{
80 | labelsContanctsView.showErrorMsg("网络不稳定");
81 | }
82 | }
83 | @Override
84 | public void onFailure(Call call, Throwable t) {
85 | labelsContanctsView.showErrorMsg("网络不稳定");
86 | }
87 | });
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/main/data/model/base/User.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.main.data.model.base;
2 |
3 |
4 | /**
5 | * Created by yuan on 16-4-1.
6 | */
7 | public class User {
8 | private int id;
9 | private String unum;
10 | private String head;
11 | private String nick;
12 | private String pass;
13 | private int sex;
14 | private int status;
15 |
16 | public int getId() {
17 | return id;
18 | }
19 |
20 | public void setId(int id) {
21 | this.id = id;
22 | }
23 |
24 |
25 | public String getUnum() {
26 | return unum;
27 | }
28 |
29 | public void setUnum(String unum) {
30 | this.unum = unum;
31 | }
32 |
33 | public String getHead() {
34 | return head;
35 | }
36 |
37 | public void setHead(String head) {
38 | this.head = head;
39 | }
40 |
41 |
42 | public String getNick() {
43 | return nick;
44 | }
45 |
46 | public void setNick(String nick) {
47 | this.nick = nick;
48 | }
49 |
50 |
51 | public String getPass() {
52 | return pass;
53 | }
54 |
55 | public void setPass(String pass) {
56 | this.pass = pass;
57 | }
58 |
59 |
60 | public int getSex() {
61 | return sex;
62 | }
63 |
64 | public void setSex(int sex) {
65 | this.sex = sex;
66 | }
67 |
68 | public int getStatus() {
69 | return status;
70 | }
71 |
72 | public void setStatus(int status) {
73 | this.status = status;
74 | }
75 |
76 | @Override
77 | public boolean equals(Object o) {
78 | if (this == o) return true;
79 | if (o == null || getClass() != o.getClass()) return false;
80 |
81 | User user = (User) o;
82 |
83 | if (id != user.id) return false;
84 | if (sex != user.sex) return false;
85 | if (status != user.status) return false;
86 | if (unum != null ? !unum.equals(user.unum) : user.unum != null) return false;
87 | if (head != null ? !head.equals(user.head) : user.head != null) return false;
88 | if (nick != null ? !nick.equals(user.nick) : user.nick != null) return false;
89 | if (pass != null ? !pass.equals(user.pass) : user.pass != null) return false;
90 |
91 | return true;
92 | }
93 |
94 | @Override
95 | public int hashCode() {
96 | int result = id;
97 | result = 31 * result + (unum != null ? unum.hashCode() : 0);
98 | result = 31 * result + (head != null ? head.hashCode() : 0);
99 | result = 31 * result + (nick != null ? nick.hashCode() : 0);
100 | result = 31 * result + (pass != null ? pass.hashCode() : 0);
101 | result = 31 * result + sex;
102 | result = 31 * result + status;
103 | return result;
104 | }
105 |
106 | @Override
107 | public String toString() {
108 | return "User{" +
109 | "id=" + id +
110 | ", unum='" + unum + '\'' +
111 | ", head='" + head + '\'' +
112 | ", nick='" + nick + '\'' +
113 | ", pass='" + pass + '\'' +
114 | ", sex=" + sex +
115 | ", status=" + status +
116 | '}';
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/yuannews/src/main/java/cn/edu/hpu/yuan/yuannews/user/center/CenterPersenter.java:
--------------------------------------------------------------------------------
1 | package cn.edu.hpu.yuan.yuannews.user.center;
2 |
3 | import java.util.List;
4 |
5 | import cn.edu.hpu.yuan.yuannews.main.app.BaseApplication;
6 | import cn.edu.hpu.yuan.yuannews.main.data.model.DataBean;
7 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.TasteVo;
8 | import cn.edu.hpu.yuan.yuannews.main.data.model.basevo.UserVo;
9 | import retrofit2.Call;
10 | import retrofit2.Callback;
11 | import retrofit2.Response;
12 |
13 | /**
14 | * Created by yuan on 16-5-12.
15 | */
16 | public class CenterPersenter implements CenterContancts.CenterContanctsPresenter {
17 |
18 | private CenterContancts.CenterContanctsView centerContanctsView;
19 |
20 |
21 | public CenterPersenter(CenterContancts.CenterContanctsView centerContanctsView) {
22 | this.centerContanctsView = centerContanctsView;
23 | }
24 |
25 | @Override
26 | public void getUserDetailData() {
27 | centerContanctsView.showDialog();
28 | Integer id = BaseApplication.newsAPIShared.getSharedUserID();
29 | BaseApplication.newsAPIService.postUserDetail(id).enqueue(new Callback>() {
30 | @Override
31 | public void onResponse(Call> call, Response> response) {
32 | if(response.isSuccessful()){
33 | DataBean body = response.body();
34 | if(body.getCode()==0){
35 | UserVo data = body.getData();
36 | if(data!=null) {
37 | centerContanctsView.showUserDetail(data);
38 | }else{
39 | centerContanctsView.showError("数据加载失败");
40 | }
41 | }else{
42 | centerContanctsView.showError(body.getMsg());
43 | }
44 |
45 | }else{
46 | centerContanctsView.showError("网络不稳定");
47 | }
48 | }
49 |
50 | @Override
51 | public void onFailure(Call> call, Throwable t) {
52 | centerContanctsView.showError("网络不稳定");
53 | }
54 | });
55 | }
56 |
57 | @Override
58 | public void getUserAllLabels() {
59 | Integer id = BaseApplication.newsAPIShared.getSharedUserID();
60 | BaseApplication.newsAPIService.postTasteVos(id).enqueue(new Callback>>() {
61 | @Override
62 | public void onResponse(Call>> call, Response>> response) {
63 |
64 | if(response.isSuccessful()){
65 | if(response.body().getCode()==0){
66 | centerContanctsView.showAllLabels(response.body().getData());
67 | }else{
68 | centerContanctsView.showError(response.body().getMsg());
69 | }
70 | }else {
71 | centerContanctsView.showError("网络不稳定");
72 | }
73 |
74 | }
75 |
76 | @Override
77 | public void onFailure(Call>> call, Throwable t) {
78 | centerContanctsView.showError("网络不稳定");
79 | }
80 | });
81 | }
82 | }
83 |
--------------------------------------------------------------------------------