diff --git a/app/src/main/java/com/gh/common/util/CollectionUtils.kt b/app/src/main/java/com/gh/common/util/CollectionUtils.kt new file mode 100644 index 0000000000..64132d240a --- /dev/null +++ b/app/src/main/java/com/gh/common/util/CollectionUtils.kt @@ -0,0 +1,111 @@ +package com.gh.common.util + +import android.content.Context +import com.gh.gamecenter.retrofit.Response +import com.gh.gamecenter.retrofit.RetrofitManager +import okhttp3.MediaType +import okhttp3.RequestBody +import okhttp3.ResponseBody +import org.json.JSONObject +import retrofit2.HttpException +import rx.Observable +import rx.android.schedulers.AndroidSchedulers +import rx.schedulers.Schedulers + +/** + * Created by khy on 26/07/17. + */ +object CollectionUtils { + + enum class CollectionTag { + tools, article + } + + + fun postCollection(conext: Context,content: String, tag: CollectionTag, listener: OnCollectionListener) { + + val body = RequestBody.create(MediaType.parse("application/json"), content) + + val postCollection: Observable + var token = LoginUtils.getToken(conext) + when (tag) { + CollectionTag.article -> postCollection = RetrofitManager.getApi().postCollectionArticle(token, body) + CollectionTag.tools -> postCollection = RetrofitManager.getApi().postCollectionTools(token, body) + } + postCollection + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : Response() { + override fun onResponse(response: ResponseBody?) { + super.onResponse(response) + + listener.onSuccess() + } + + override fun onFailure(e: HttpException?) { + super.onFailure(e) + if (e != null) { + var string = e.response()?.errorBody()?.string() + var errorBody = JSONObject(string) + if (errorBody.getInt("status") == 40031) { + listener.onSuccess() + return + } + } + listener.onError() + } + }) + } + + fun deleteCollection(conext: Context, id: String, tag: CollectionTag, listener: OnCollectionListener) { + + val postCollection: Observable + when (tag) { + CollectionTag.article -> postCollection = RetrofitManager.getApi().deletaCollectionArticle(LoginUtils.getToken(conext), id) + CollectionTag.tools -> postCollection = RetrofitManager.getApi().deleteCollectionTools(LoginUtils.getToken(conext), id) + } + postCollection + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : Response() { + override fun onResponse(response: ResponseBody?) { + super.onResponse(response) + listener.onSuccess() + } + + override fun onFailure(e: HttpException?) { + super.onFailure(e) + listener.onError() + } + }) + } + + fun patchCollection(conext: Context, id: String, tag: CollectionTag) { + val postCollection: Observable + when (tag) { + CollectionTag.article -> postCollection = RetrofitManager.getApi().patchCollectionArticle(LoginUtils.getToken(conext), id) + CollectionTag.tools -> postCollection = RetrofitManager.getApi().patchCollectionTools(LoginUtils.getToken(conext), id) + } + postCollection + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : Response() { + override fun onResponse(response: ResponseBody?) { + super.onResponse(response) + } + + override fun onFailure(e: HttpException?) { + super.onFailure(e) + } + }) + } + + + + + interface OnCollectionListener { + fun onSuccess() + fun onError() + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/util/LoginUtils.java b/app/src/main/java/com/gh/common/util/LoginUtils.java index 76b86f9da0..56f7fdcdd7 100644 --- a/app/src/main/java/com/gh/common/util/LoginUtils.java +++ b/app/src/main/java/com/gh/common/util/LoginUtils.java @@ -298,6 +298,21 @@ public class LoginUtils { return null; } + //获取本地缓存用户token + public static String getToken(Context context) { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); + String loginData = sp.getString("login_token", null); + if (!TextUtils.isEmpty(loginData)) { + Type listType = new TypeToken() { + }.getType(); + LoginResponseEntity entity = new Gson().fromJson(loginData, listType); + if (entity != null && entity.getAccessToken() != null) { + return entity.getAccessToken().getValue(); + } + } + return null; + } + // 在本地缓存用户token public static void saveLoginToken(Context context, LoginResponseEntity entity) { if (entity != null) { diff --git a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java index 93bcbb37d2..10a334a7db 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java @@ -26,6 +26,7 @@ import com.gh.base.BaseActivity; import com.gh.base.OnRequestCallBackListener; import com.gh.common.util.ApkActiveUtils; import com.gh.common.util.CheckLoginUtils; +import com.gh.common.util.CollectionUtils; import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DetailDownloadUtils; @@ -35,6 +36,7 @@ import com.gh.common.util.ShareUtils; import com.gh.common.view.VerticalItemDecoration; import com.gh.download.DownloadManager; import com.gh.gamecenter.adapter.viewholder.DetailViewHolder; +import com.gh.gamecenter.db.CollectionDao; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.eventbus.EBConcernChanged; @@ -44,9 +46,11 @@ import com.gh.gamecenter.eventbus.EBPackage; import com.gh.gamecenter.newsdetail.NewsDetailAdapter; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; +import com.google.gson.Gson; import com.jakewharton.rxbinding.view.RxView; import com.lightgame.download.DataWatcher; import com.lightgame.download.DownloadEntity; +import com.lightgame.utils.Utils; import com.tencent.tauth.Tencent; import org.greenrobot.eventbus.Subscribe; @@ -89,12 +93,13 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, @BindView(R.id.news_detail_share) ImageView mNewsShare; @BindView(R.id.news_detail_collection) - ImageView mNewsCllection; + ImageView mNewsCollection; private NewsDetailAdapter adapter; private boolean isSentReport = false; private boolean isSecondDown = false; + private boolean mIsCollectionNews; private float Y11, Y12, Y21, Y22; private float X11, X12, X21, X22; private double R11; @@ -107,7 +112,10 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, private SharedPreferences sp; + private CollectionDao mCollectionDao; + private GameEntity gameEntity; + private NewsEntity mNewsEntity; private DownloadEntity mDownloadEntity; private Handler handler = new Handler(); @@ -136,15 +144,13 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, if (newsId != null) { getNewsDigest(newsId); } else { - String id = getIntent().getStringExtra("id"); - String type = getIntent().getStringExtra("type"); - String title = getIntent().getStringExtra("title"); - if (type != null) { - mActionbarTitle.setText(type); + if (mNewsEntity == null) return; + if (mNewsEntity.getType() != null) { + mActionbarTitle.setText(mNewsEntity.getType()); } - adapter.setId(id); - adapter.setType(type); - adapter.setTitle(title); + adapter.setId(mNewsEntity.getId()); + adapter.setType(mNewsEntity.getType()); + adapter.setTitle(mNewsEntity.getTitle()); adapter.getNewsDetail(); } } @@ -170,15 +176,37 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, } else { Intent intent = new Intent(context, NewsDetailActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra("id", newsEntity.getId()); - intent.putExtra("title", newsEntity.getTitle()); - intent.putExtra("type", newsEntity.getType()); intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance); + intent.putExtra(NewsEntity.class.getSimpleName(), newsEntity); context.startActivity(intent); } } + + /** + * 在收藏启动新闻详情页面 + */ + public static void startNewsDetailByCollection(Context context, NewsEntity newsEntity, String entrance) { + if (!TextUtils.isEmpty(newsEntity.getLink())) { + Intent intent = new Intent(context, WebActivity.class); + intent.putExtra("url", newsEntity.getLink()); + intent.putExtra("gameName", newsEntity.getGameName()); + intent.putExtra("newsId", newsEntity.getId()); + intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance + "+(消息详情[" + newsEntity.getGameName() + "])"); + context.startActivity(intent); + } else { + Intent intent = new Intent(context, NewsDetailActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance); + intent.putExtra(NewsEntity.class.getSimpleName(), newsEntity); + intent.putExtra("isCollectionNews", true); + context.startActivity(intent); + } + + } + + @NonNull public static Intent getIntentById(Context context, String newsId, String entrance) { Intent intent = new Intent(context, NewsDetailActivity.class); @@ -219,6 +247,8 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, initTitle(""); + mCollectionDao = new CollectionDao(this); + mDetailRv.setHasFixedSize(true); mDetailRv.setLayoutManager(new LinearLayoutManager(this)); mDetailRv.addItemDecoration(new VerticalItemDecoration(this, 8, false)); @@ -226,22 +256,28 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, mDetailRv.setAdapter(adapter); newsId = getIntent().getStringExtra("newsId"); + mIsCollectionNews = getIntent().getBooleanExtra("isCollectionNews", false); if (getIntent().getBundleExtra("data") != null) { newsId = getIntent().getBundleExtra("data").getString("newsId"); } if (newsId == null) { - String id = getIntent().getStringExtra("id"); - String type = getIntent().getStringExtra("type"); - String title = getIntent().getStringExtra("title"); - if (type != null) { - mActionbarTitle.setText(type); - } - adapter.setId(id); - adapter.setType(type); - adapter.setTitle(title); - adapter.getNewsDetail(); + mNewsEntity = getIntent().getParcelableExtra(NewsEntity.class.getSimpleName()); + if (mNewsEntity != null) { + if (mNewsEntity.getType() != null) { + mActionbarTitle.setText(mNewsEntity.getType()); + } + adapter.setId(mNewsEntity.getId()); + adapter.setType(mNewsEntity.getType()); + adapter.setTitle(mNewsEntity.getTitle()); + adapter.getNewsDetail(); + mNewsShare.setVisibility(View.VISIBLE); - mNewsShare.setVisibility(View.VISIBLE); + if (mIsCollectionNews) { + getNewsDigest(mNewsEntity.getId()); + } + + initCollection(); + } } else { getNewsDigest(newsId); } @@ -270,6 +306,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, mNoConn.setOnClickListener(this); mDetailCommentLl.setOnClickListener(this); + mNewsCollection.setOnClickListener(this); // 防抖处理 RxView.clicks(mNewsShare) @@ -301,6 +338,19 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, }); } + private void initCollection() { + if (mNewsEntity != null) { + boolean exist = mCollectionDao.isExist(mNewsEntity.getId()); + mNewsCollection.setVisibility(View.VISIBLE); + if (exist) { + mNewsCollection.setImageResource(R.drawable.detail_collection_select); + } else { + mNewsCollection.setImageResource(R.drawable.detail_collection_unselect); + } + } + } + + @Override protected void onDestroy() { super.onDestroy(); @@ -393,6 +443,20 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, .subscribe(new Response() { @Override public void onResponse(NewsEntity response) { + if (mIsCollectionNews && mNewsEntity != null && response != null) { // 对比查看收藏文章是否修改 + Gson gson = new Gson(); + + String newEntity = gson.toJson(response); + String entity = gson.toJson(mNewsEntity); + if (!newEntity.equals(entity)) { + CollectionUtils.INSTANCE.patchCollection(NewsDetailActivity.this, response.getId(), CollectionUtils.CollectionTag.article); + } else { + Utils.log("========相同"); + } + return; + } + + mNewsEntity = response; if (response.getType() != null) { mActionbarTitle.setText(response.getType()); } @@ -403,6 +467,8 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, adapter.getNewsDetail(); mNewsShare.setVisibility(View.VISIBLE); + + initCollection(); } @Override @@ -500,8 +566,50 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener, startActivity(intent); } }); - } else if (v == mNewsCllection) { - // TODO 收藏 + } else if (v == mNewsCollection) { + CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() { + @Override + public void onLoggedIn() { + mNewsCollection.setEnabled(false); + if (mCollectionDao.isExist(mNewsEntity.getId())) { + CollectionUtils.INSTANCE.deleteCollection(NewsDetailActivity.this, mNewsEntity.getId(), + CollectionUtils.CollectionTag.article, + new CollectionUtils.OnCollectionListener() { + @Override + public void onSuccess() { + mCollectionDao.delete(mNewsEntity.getId()); + mNewsCollection.setEnabled(true); + mNewsCollection.setImageResource(R.drawable.detail_collection_unselect); + } + + @Override + public void onError() { + mNewsCollection.setEnabled(true); + toast("取消收藏失败"); + } + }); + + } else { + String content = new Gson().toJson(mNewsEntity); + CollectionUtils.INSTANCE.postCollection(NewsDetailActivity.this, content, + CollectionUtils.CollectionTag.article, + new CollectionUtils.OnCollectionListener() { + @Override + public void onSuccess() { + mCollectionDao.add(mNewsEntity.getId()); + mNewsCollection.setEnabled(true); + mNewsCollection.setImageResource(R.drawable.detail_collection_select); + } + + @Override + public void onError() { + mNewsCollection.setEnabled(true); + toast("收藏失败"); + } + }); + } + } + }); } } diff --git a/app/src/main/java/com/gh/gamecenter/WebActivity.java b/app/src/main/java/com/gh/gamecenter/WebActivity.java index a8085d8793..aeaaf74632 100644 --- a/app/src/main/java/com/gh/gamecenter/WebActivity.java +++ b/app/src/main/java/com/gh/gamecenter/WebActivity.java @@ -19,12 +19,17 @@ import android.widget.RelativeLayout; import android.widget.TextView; import com.gh.base.BaseActivity; +import com.gh.common.util.CheckLoginUtils; +import com.gh.common.util.CollectionUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.EntranceUtils; import com.gh.common.util.ShareUtils; +import com.gh.gamecenter.db.CollectionDao; import com.gh.gamecenter.entity.CommentnumEntity; import com.gh.gamecenter.entity.ToolBoxEntity; +import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; +import com.google.gson.Gson; import com.jakewharton.rxbinding.view.RxView; import com.tencent.tauth.Tencent; @@ -61,8 +66,11 @@ public class WebActivity extends BaseActivity { private int commentNum; private boolean mIsTools; + private boolean mIsCollectionTools; private ToolBoxEntity mToolBoxEntity; + private CollectionDao mCollectionDao; + @NonNull public static Intent getWebIntent(Context context) { Intent intent = new Intent(context, WebActivity.class); @@ -71,6 +79,17 @@ public class WebActivity extends BaseActivity { return intent; } + @NonNull + public static void startWebByCollectionTools(Context context, ToolBoxEntity toolBoxEntity) { + Intent intent = new Intent(context, WebActivity.class); + intent.putExtra("url", toolBoxEntity.getUrl()); + intent.putExtra("isTools", true); + intent.putExtra("gameName", toolBoxEntity.getName()); + intent.putExtra("ToolBoxEntity", toolBoxEntity); + intent.putExtra("isCollectionTools", true); + context.startActivity(intent); + } + @Override protected int getLayoutId() { return R.layout.activity_web; @@ -106,9 +125,12 @@ public class WebActivity extends BaseActivity { } if (mIsTools) { + mCollectionDao = new CollectionDao(this); mToolBoxEntity = getIntent().getParcelableExtra("ToolBoxEntity"); + mIsCollectionTools = getIntent().getBooleanExtra("isCollectionTools", false); mShareIv.setVisibility(View.VISIBLE); mCollectionIv.setVisibility(View.VISIBLE); + initCollection(); } else { mShareIv.setVisibility(View.GONE); mCollectionIv.setVisibility(View.GONE); @@ -177,7 +199,6 @@ public class WebActivity extends BaseActivity { newsTitle.setPadding(DisplayUtils.dip2px(getApplication(), 30), 0, DisplayUtils.dip2px(getApplication(), 30), 0); newsTitle.setSingleLine(); newsTitle.setText(title); - } } }); @@ -196,6 +217,47 @@ public class WebActivity extends BaseActivity { } }); } + + if (mIsCollectionTools && mToolBoxEntity != null) { + getToolsById(); // 对比查看是否修改 + } + } + + private void initCollection() { + if (mToolBoxEntity != null) { + boolean exist = mCollectionDao.isExist(mToolBoxEntity.getId()); + mCollectionIv.setVisibility(View.VISIBLE); + if (exist) { + mCollectionIv.setImageResource(R.drawable.detail_collection_select); + } else { + mCollectionIv.setImageResource(R.drawable.detail_collection_unselect); + } + } + } + + + private void getToolsById() { + RetrofitManager + .getApi() + .getToolBoxById(mToolBoxEntity.getId()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>() { + @Override + public void onResponse(List response) { + super.onResponse(response); + if (response.size() == 0) return; + + ToolBoxEntity toolBoxEntity = response.get(0); + Gson gson = new Gson(); + + String newEntity = gson.toJson(toolBoxEntity); + String entity = gson.toJson(mToolBoxEntity); + if (!newEntity.equals(entity)) { + CollectionUtils.INSTANCE.patchCollection(WebActivity.this, toolBoxEntity.getId(), CollectionUtils.CollectionTag.tools); + } + } + }); } public void getNewsCommentNum() { @@ -225,7 +287,49 @@ public class WebActivity extends BaseActivity { intent.putExtra(EntranceUtils.KEY_ENTRANCE, mEntrance + "+(光环浏览器)"); startActivityForResult(intent, 1001); } else if (v == mCollectionIv) { - // TODO 收藏 + CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() { + @Override + public void onLoggedIn() { + mCollectionIv.setEnabled(false); + if (mCollectionDao.isExist(mToolBoxEntity.getId())) { + CollectionUtils.INSTANCE.deleteCollection(WebActivity.this, mToolBoxEntity.getId(), + CollectionUtils.CollectionTag.tools, + new CollectionUtils.OnCollectionListener() { + @Override + public void onSuccess() { + mCollectionDao.delete(mToolBoxEntity.getId()); + mCollectionIv.setEnabled(true); + mCollectionIv.setImageResource(R.drawable.detail_collection_unselect); + } + + @Override + public void onError() { + mCollectionIv.setEnabled(true); + toast("取消收藏失败"); + } + }); + + } else { + String content = new Gson().toJson(mToolBoxEntity); + CollectionUtils.INSTANCE.postCollection(WebActivity.this, content, + CollectionUtils.CollectionTag.tools, + new CollectionUtils.OnCollectionListener() { + @Override + public void onSuccess() { + mCollectionDao.add(mToolBoxEntity.getId()); + mCollectionIv.setEnabled(true); + mCollectionIv.setImageResource(R.drawable.detail_collection_select); + } + + @Override + public void onError() { + mCollectionIv.setEnabled(true); + toast("收藏失败"); + } + }); + } + } + }); } } diff --git a/app/src/main/java/com/gh/gamecenter/collection/ArticleAdapter.java b/app/src/main/java/com/gh/gamecenter/collection/ArticleAdapter.java index 7ab46a84e0..43a8b7f8ef 100644 --- a/app/src/main/java/com/gh/gamecenter/collection/ArticleAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/collection/ArticleAdapter.java @@ -7,12 +7,15 @@ import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.LinearLayout; +import android.widget.Toast; +import com.gh.base.OnRequestCallBackListener; import com.gh.common.constant.ItemViewType; import com.gh.common.util.DataCollectionUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.ImageUtils; +import com.gh.common.util.LoginUtils; import com.gh.common.util.NewsUtils; import com.gh.gamecenter.NewsDetailActivity; import com.gh.gamecenter.R; @@ -21,8 +24,11 @@ import com.gh.gamecenter.adapter.viewholder.NewsImage1ViewHolder; import com.gh.gamecenter.adapter.viewholder.NewsImage2ViewHolder; import com.gh.gamecenter.adapter.viewholder.NewsImage3ViewHolder; import com.gh.gamecenter.entity.NewsEntity; +import com.gh.gamecenter.entity.ViewsEntity; import com.gh.gamecenter.manager.VisitManager; import com.gh.gamecenter.retrofit.JSONObjectResponse; +import com.gh.gamecenter.retrofit.ObservableUtil; +import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.adapter.BaseRecyclerAdapter; @@ -35,7 +41,12 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import retrofit2.HttpException; +import rx.Observable; +import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Action1; +import rx.functions.Func1; import rx.schedulers.Schedulers; /** @@ -44,14 +55,133 @@ import rx.schedulers.Schedulers; public class ArticleAdapter extends BaseRecyclerAdapter { + private OnRequestCallBackListener mListener; + private List mNewsList; + private boolean isLoading; + private boolean isOver; + private boolean isNetworkError; - public ArticleAdapter(Context context) { + + public ArticleAdapter(Context context , OnRequestCallBackListener listener) { super(context); + mListener = listener; mNewsList = new ArrayList<>(); } + public void addList(final int offset) { + if (isLoading) { + return; + } + isLoading = true; + RetrofitManager + .getApi() + .getCollectionArticle(LoginUtils.getToken(mContext), offset) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>(){ + @Override + public void onResponse(List response) { + super.onResponse(response); + isLoading = false; + + if (response.size() != 0) { + mNewsList.addAll(response); +// if (!fragment.isHidden() && !fragment.isEverPause()) { +// notifyItemRangeInserted(newsList.size() - response.size(), response.size()); +// } else { + notifyDataSetChanged(); +// } + } else { + isOver = true; + notifyItemChanged(getItemCount() - 1); + } + + if (offset == 0 && mListener != null) { + if (mNewsList.size() == 0) { + mListener.loadEmpty(); + } else { + mListener.loadDone(); + } + } + + if (response.size() < 20) { + isOver = true; + } + + // 获取新闻阅读量 + getNewsViews(response, offset); + } + + @Override + public void onFailure(HttpException e) { + super.onFailure(e); + isLoading = false; + // 网络错误 + if (offset == 0) { + if (mListener != null) { + mListener.loadError(); + } + } else { + Toast.makeText(mContext, "加载失败,请检查网络状态", Toast.LENGTH_SHORT).show(); + isNetworkError = true; + notifyItemChanged(getItemCount() - 1); + } + } + }); + } + + // 获取新闻阅读量 + private void getNewsViews(final List list, final int start) { + if (list == null || list.isEmpty()) { + return; + } + ObservableUtil.computation(new Observable.OnSubscribe() { + @Override + public void call(Subscriber subscriber) { + StringBuilder builder = new StringBuilder(); + for (int i = 0, size = list.size(); i < size; i++) { + builder.append(list.get(i).getId()); + builder.append("-"); + } + builder.deleteCharAt(builder.length() - 1); + String ids = builder.toString(); + VisitManager.getInstance().addUrl(ids); + subscriber.onNext(ids); + subscriber.onCompleted(); + } + }, new Action1() { + @Override + public void call(String ids) { + RetrofitManager.getData() + .getNewsViews(ids) + .map(new Func1, String>() { + @Override + public String call(List list) { + for (ViewsEntity viewsEntity : list) { + for (NewsEntity newsEntity : mNewsList) { + if (viewsEntity.getId().equals(newsEntity.getId())) { + newsEntity.setViews(viewsEntity.getViews()); + break; + } + } + } + return null; + } + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onResponse(String response) { + notifyItemRangeChanged(start, list.size()); + } + }); + } + }); + } + @Override public int getItemViewType(int position) { if (position == mNewsList.size()) { @@ -117,13 +247,13 @@ public class ArticleAdapter extends BaseRecyclerAdapter { Map kv = new HashMap<>(); kv.put("名字", newsEntity.getTitle()); kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); - DataUtils.onEvent(mContext, "点击", "资讯-资讯", kv); + DataUtils.onEvent(mContext, "点击", "收藏-文章", kv); - DataCollectionUtils.uploadClick(mContext, "列表", "资讯-资讯", newsEntity.getTitle()); + DataCollectionUtils.uploadClick(mContext, "列表", "收藏-文章", newsEntity.getTitle()); //统计阅读量 statNewsViews(newsEntity, viewHolder.getPosition()); - NewsDetailActivity.startNewsDetailActivity(mContext, newsEntity, "(资讯:资讯[2-1])"); + NewsDetailActivity.startNewsDetailByCollection(mContext, newsEntity, "(收藏:文章)"); } }); ImageUtils.Companion.display(viewHolder.thumb, newsEntity.getThumbnail().getUrl().get(0)); @@ -165,13 +295,13 @@ public class ArticleAdapter extends BaseRecyclerAdapter { Map kv = new HashMap<>(); kv.put("名字", newsEntity.getTitle()); kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); - DataUtils.onEvent(mContext, "点击", "资讯-资讯", kv); + DataUtils.onEvent(mContext, "点击", "收藏-文章", kv); - DataCollectionUtils.uploadClick(mContext, "列表", "资讯-资讯", newsEntity.getTitle()); + DataCollectionUtils.uploadClick(mContext, "列表", "收藏-文章", newsEntity.getTitle()); //统计阅读量 statNewsViews(newsEntity, viewHolder.getPosition()); - NewsDetailActivity.startNewsDetailActivity(mContext, newsEntity, "(资讯:资讯[2-1])"); + NewsDetailActivity.startNewsDetailByCollection(mContext, newsEntity, "(收藏:文章)"); } }); viewHolder.title.setText(newsEntity.getTitle()); @@ -198,13 +328,13 @@ public class ArticleAdapter extends BaseRecyclerAdapter { Map kv = new HashMap<>(); kv.put("名字", newsEntity.getTitle()); kv.put("位置", String.valueOf(viewHolder.getPosition() + 1)); - DataUtils.onEvent(mContext, "点击", "资讯-资讯", kv); + DataUtils.onEvent(mContext, "点击", "收藏-文章", kv); - DataCollectionUtils.uploadClick(mContext, "列表", "资讯-资讯", newsEntity.getTitle()); + DataCollectionUtils.uploadClick(mContext, "列表", "收藏-文章", newsEntity.getTitle()); //统计阅读量 statNewsViews(newsEntity, viewHolder.getPosition()); - NewsDetailActivity.startNewsDetailActivity(mContext, newsEntity, "(资讯:资讯[2-1])"); + NewsDetailActivity.startNewsDetailByCollection(mContext, newsEntity, "(收藏:文章)"); } }); viewHolder.title.setText(newsEntity.getTitle()); @@ -222,28 +352,28 @@ public class ArticleAdapter extends BaseRecyclerAdapter { private void initFooterViewHolder(FooterViewHolder viewHolder) { -// viewHolder.initItemPadding(); -// if (isNetworkError) { -// viewHolder.loading.setVisibility(View.GONE); -// viewHolder.hint.setText("加载失败,点击重试"); -// viewHolder.itemView.setClickable(true); -// viewHolder.itemView.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// isNetworkError = false; -// notifyItemChanged(getItemCount() - 1); -// addList(newsList.size()); -// } -// }); -// } else if (isOver) { -// viewHolder.loading.setVisibility(View.GONE); -// viewHolder.hint.setText("加载完毕"); -// viewHolder.itemView.setClickable(false); -// } else { -// viewHolder.loading.setVisibility(View.VISIBLE); -// viewHolder.hint.setText(R.string.loading); -// viewHolder.itemView.setClickable(false); -// } + viewHolder.initItemPadding(); + if (isNetworkError) { + viewHolder.loading.setVisibility(View.GONE); + viewHolder.hint.setText("加载失败,点击重试"); + viewHolder.itemView.setClickable(true); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + isNetworkError = false; + notifyItemChanged(getItemCount() - 1); + addList(mNewsList.size()); + } + }); + } else if (isOver) { + viewHolder.loading.setVisibility(View.GONE); + viewHolder.hint.setText("加载完毕"); + viewHolder.itemView.setClickable(false); + } else { + viewHolder.loading.setVisibility(View.VISIBLE); + viewHolder.hint.setText(R.string.loading); + viewHolder.itemView.setClickable(false); + } } // 统计新闻阅读量 diff --git a/app/src/main/java/com/gh/gamecenter/collection/ArticleFragment.java b/app/src/main/java/com/gh/gamecenter/collection/ArticleFragment.java index 8e27dc0ad6..f5ebd158c1 100644 --- a/app/src/main/java/com/gh/gamecenter/collection/ArticleFragment.java +++ b/app/src/main/java/com/gh/gamecenter/collection/ArticleFragment.java @@ -2,10 +2,14 @@ package com.gh.gamecenter.collection; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.LinearLayout; import com.gh.base.fragment.BaseFragment; +import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.R; import butterknife.BindView; @@ -14,13 +18,28 @@ import butterknife.BindView; * Created by khy on 18/07/17. */ -public class ArticleFragment extends BaseFragment { +public class ArticleFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener { @BindView(R.id.article_rv) RecyclerView mRecyclerView; + @BindView(R.id.article_refresh) + SwipeRefreshLayout mRefreshLayout; + @BindView(R.id.reuse_no_connection) + LinearLayout mNoConn; + @BindView(R.id.reuse_none_data) + LinearLayout mNoData; private ArticleAdapter mAdapter; + Runnable runnable = new Runnable() { + @Override + public void run() { + mAdapter = new ArticleAdapter(getContext(), ArticleFragment.this); + mRecyclerView.setAdapter(mAdapter); + mAdapter.addList(0); + } + }; + @Override protected int getLayoutId() { return R.layout.fragment_article; @@ -29,9 +48,45 @@ public class ArticleFragment extends BaseFragment { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mRefreshLayout.setColorSchemeResources(R.color.theme); + mRefreshLayout.setOnRefreshListener(this); + mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - mAdapter = new ArticleAdapter(getContext()); + mAdapter = new ArticleAdapter(getContext(), this); mRecyclerView.setAdapter(mAdapter); + mRecyclerView.addItemDecoration(new VerticalItemDecoration(getContext(), 8, true)); + mAdapter.addList(0); + } + + @Override + public void loadDone() { // 数据加载成功回调 + mRefreshLayout.setRefreshing(false); + mRecyclerView.setVisibility(View.VISIBLE); + mNoConn.setVisibility(View.GONE); + mNoData.setVisibility(View.GONE); + } + + @Override + public void loadError() { // 数据加载失败回调 + mRefreshLayout.setRefreshing(false); + mRecyclerView.setVisibility(View.GONE); + mNoConn.setVisibility(View.VISIBLE); + mNoData.setVisibility(View.GONE); + } + + @Override + public void loadEmpty() { + super.loadEmpty(); + mRefreshLayout.setRefreshing(false); + mRecyclerView.setVisibility(View.GONE); + mNoConn.setVisibility(View.GONE); + mNoData.setVisibility(View.VISIBLE); + } + + + @Override + public void onRefresh() { + view.postDelayed(runnable, 1000); } } diff --git a/app/src/main/java/com/gh/gamecenter/collection/CollectionFragment.java b/app/src/main/java/com/gh/gamecenter/collection/CollectionFragment.java index 4ef9902825..ec41fe5fa8 100644 --- a/app/src/main/java/com/gh/gamecenter/collection/CollectionFragment.java +++ b/app/src/main/java/com/gh/gamecenter/collection/CollectionFragment.java @@ -56,8 +56,8 @@ public class CollectionFragment extends BaseFragment_ViewPager_Checkable { @Override protected void initFragmentList(List fragments) { - fragments.add(new ArticleFragment()); fragments.add(new ToolsFragment()); + fragments.add(new ArticleFragment()); } @Override diff --git a/app/src/main/java/com/gh/gamecenter/collection/ToolsAdapter.java b/app/src/main/java/com/gh/gamecenter/collection/ToolsAdapter.java index 3a0884edd6..46b4cdfa71 100644 --- a/app/src/main/java/com/gh/gamecenter/collection/ToolsAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/collection/ToolsAdapter.java @@ -6,33 +6,109 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; +import com.gh.base.OnRequestCallBackListener; import com.gh.common.util.EntranceUtils; import com.gh.common.util.ImageUtils; +import com.gh.common.util.LoginUtils; import com.gh.gamecenter.NewsDetailActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.WebActivity; import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; import com.gh.gamecenter.adapter.viewholder.ToolBoxViewHolder; import com.gh.gamecenter.entity.ToolBoxEntity; +import com.gh.gamecenter.retrofit.Response; +import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.adapter.BaseRecyclerAdapter; import java.util.ArrayList; import java.util.List; +import retrofit2.HttpException; +import rx.android.schedulers.AndroidSchedulers; +import rx.schedulers.Schedulers; + /** * Created by khy on 18/07/17. */ public class ToolsAdapter extends BaseRecyclerAdapter { + private OnRequestCallBackListener mListener; + private List mEntityList; - public ToolsAdapter(Context context) { + private boolean isLoading; + private boolean isOver; + private boolean isNetworkError; + + public ToolsAdapter(Context context, OnRequestCallBackListener listener) { super(context); + mListener = listener; mEntityList = new ArrayList<>(); } + public void addList(final int offset) { + if (isLoading) { + return; + } + isLoading = true; + RetrofitManager + .getApi() + .getCollectionTools(LoginUtils.getToken(mContext), offset) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response>(){ + @Override + public void onResponse(List response) { + super.onResponse(response); + isLoading = false; + + if (response.size() != 0) { + mEntityList.addAll(response); +// if (!fragment.isHidden() && !fragment.isEverPause()) { +// notifyItemRangeInserted(newsList.size() - response.size(), response.size()); +// } else { + notifyDataSetChanged(); +// } + } else { + isOver = true; + notifyItemChanged(getItemCount() - 1); + } + + if (offset == 0 && mListener != null) { + if (mEntityList.size() == 0) { + mListener.loadEmpty(); + } else { + mListener.loadDone(); + } + } + + if (response.size() < 20) { + isOver = true; + } + + } + + @Override + public void onFailure(HttpException e) { + super.onFailure(e); + isLoading = false; + // 网络错误 + if (offset == 0) { + if (mListener != null) { + mListener.loadError(); + } + } else { + Toast.makeText(mContext, "加载失败,请检查网络状态", Toast.LENGTH_SHORT).show(); + isNetworkError = true; + notifyItemChanged(getItemCount() - 1); + } + } + }); + } + @Override public int getItemViewType(int position) { if (position == getItemCount() - 1) { @@ -57,11 +133,11 @@ public class ToolsAdapter extends BaseRecyclerAdapter { public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof ToolBoxViewHolder) { ToolBoxViewHolder viewHolder = (ToolBoxViewHolder) holder; - ToolBoxEntity toolBoxEntity = mEntityList.get(position - 2); + ToolBoxEntity toolBoxEntity = mEntityList.get(position); initToolsViewHolder(viewHolder, toolBoxEntity); } else if (holder instanceof FooterViewHolder) { FooterViewHolder viewHolder = (FooterViewHolder) holder; -// initFooterViewHolder(viewHolder, position); + initFooterViewHolder(viewHolder); } } @@ -70,6 +146,31 @@ public class ToolsAdapter extends BaseRecyclerAdapter { return mEntityList.size() + 1; } + private void initFooterViewHolder(FooterViewHolder viewHolder) { + viewHolder.initItemPadding(); + if (isNetworkError) { + viewHolder.loading.setVisibility(View.GONE); + viewHolder.hint.setText("加载失败,点击重试"); + viewHolder.itemView.setClickable(true); + viewHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + isNetworkError = false; + notifyItemChanged(getItemCount() - 1); + addList(mEntityList.size()); + } + }); + } else if (isOver) { + viewHolder.loading.setVisibility(View.GONE); + viewHolder.hint.setText("加载完毕"); + viewHolder.itemView.setClickable(false); + } else { + viewHolder.loading.setVisibility(View.VISIBLE); + viewHolder.hint.setText(R.string.loading); + viewHolder.itemView.setClickable(false); + } + } + private void initToolsViewHolder(ToolBoxViewHolder viewHolder, final ToolBoxEntity toolBoxEntity) { viewHolder.mDes.setText(toolBoxEntity.getDes()); viewHolder.mTitle.setText(toolBoxEntity.getName()); @@ -81,17 +182,14 @@ public class ToolsAdapter extends BaseRecyclerAdapter { String url = toolBoxEntity.getUrl(); if (url.contains("http://www.ghzs666.com/article/")) { String newsId = url.substring(url.lastIndexOf("/") + 1, url.length() - 5); + Intent intent = new Intent(mContext, NewsDetailActivity.class); intent.putExtra("newsId", newsId); - intent.putExtra(EntranceUtils.KEY_ENTRANCE, "工具箱列表"); + intent.putExtra("isCollectionNews", true); + intent.putExtra(EntranceUtils.KEY_ENTRANCE, "(收藏:工具箱)"); mContext.startActivity(intent); } else { - Intent intent = new Intent(mContext, WebActivity.class); - intent.putExtra("url", toolBoxEntity.getUrl()); - intent.putExtra("isTools", true); - intent.putExtra("gameName", toolBoxEntity.getName()); - intent.putExtra("ToolBoxEntity", toolBoxEntity); - mContext.startActivity(intent); + WebActivity.startWebByCollectionTools(mContext, toolBoxEntity); } } }); diff --git a/app/src/main/java/com/gh/gamecenter/collection/ToolsFragment.java b/app/src/main/java/com/gh/gamecenter/collection/ToolsFragment.java index 458be03887..6273e17b0f 100644 --- a/app/src/main/java/com/gh/gamecenter/collection/ToolsFragment.java +++ b/app/src/main/java/com/gh/gamecenter/collection/ToolsFragment.java @@ -2,10 +2,14 @@ package com.gh.gamecenter.collection; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.LinearLayout; import com.gh.base.fragment.BaseFragment; +import com.gh.common.view.VerticalItemDecoration; import com.gh.gamecenter.R; import butterknife.BindView; @@ -14,13 +18,29 @@ import butterknife.BindView; * Created by khy on 18/07/17. */ -public class ToolsFragment extends BaseFragment { +public class ToolsFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener { @BindView(R.id.tools_rv) RecyclerView mRecyclerView; + @BindView(R.id.tools_refresh) + SwipeRefreshLayout mRefreshLayout; + @BindView(R.id.reuse_no_connection) + LinearLayout mNoConn; + @BindView(R.id.reuse_none_data) + LinearLayout mNoData; private ToolsAdapter mAdapter; + Runnable runnable = new Runnable() { + @Override + public void run() { + mAdapter = new ToolsAdapter(getContext(), ToolsFragment.this); + mRecyclerView.setAdapter(mAdapter); + mAdapter.addList(0); + } + }; + + @Override protected int getLayoutId() { return R.layout.fragment_tools; @@ -29,8 +49,44 @@ public class ToolsFragment extends BaseFragment { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mRefreshLayout.setColorSchemeResources(R.color.theme); + mRefreshLayout.setOnRefreshListener(this); + mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - mAdapter = new ToolsAdapter(getContext()); + mAdapter = new ToolsAdapter(getContext(), this); + mRecyclerView.addItemDecoration(new VerticalItemDecoration(getContext(), 8, true)); mRecyclerView.setAdapter(mAdapter); + mAdapter.addList(0); + } + + + @Override + public void loadDone() { // 数据加载成功回调 + mRefreshLayout.setRefreshing(false); + mRecyclerView.setVisibility(View.VISIBLE); + mNoConn.setVisibility(View.GONE); + mNoData.setVisibility(View.GONE); + } + + @Override + public void loadError() { // 数据加载失败回调 + mRefreshLayout.setRefreshing(false); + mRecyclerView.setVisibility(View.GONE); + mNoConn.setVisibility(View.VISIBLE); + mNoData.setVisibility(View.GONE); + } + + @Override + public void loadEmpty() { + super.loadEmpty(); + mRefreshLayout.setRefreshing(false); + mRecyclerView.setVisibility(View.GONE); + mNoConn.setVisibility(View.GONE); + mNoData.setVisibility(View.VISIBLE); + } + + @Override + public void onRefresh() { + view.postDelayed(runnable, 1000); } } diff --git a/app/src/main/java/com/gh/gamecenter/db/CollectionDao.java b/app/src/main/java/com/gh/gamecenter/db/CollectionDao.java new file mode 100644 index 0000000000..da8b541708 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/db/CollectionDao.java @@ -0,0 +1,61 @@ +package com.gh.gamecenter.db; + +import android.content.Context; + +import com.gh.gamecenter.db.info.CollectionInfo; +import com.j256.ormlite.dao.Dao; +import com.lightgame.utils.Utils; + +import java.sql.SQLException; +import java.util.List; + +/** + * Created by khy on 28/07/17. + */ + +public class CollectionDao { + + private DatabaseHelper helper; + private Dao dao; + + public CollectionDao(Context context) { + try { + helper = DatabaseHelper.getHelper(context); + dao = helper.getDao(CollectionInfo.class); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + + + public void add(String id) { + try { + dao.create(new CollectionInfo(id)); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void delete(String id) { + try { + dao.deleteById(id); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public boolean isExist(String id) { + try { + List collectionInfos = dao.queryForAll(); + for (CollectionInfo collectionInfo : collectionInfos) { + Utils.log(collectionInfo.getCollectionId() + "===" + id); + } + if (dao.queryForId(id) != null) return true; + } catch (SQLException e) { + e.printStackTrace(); + } + + return false; + } +} diff --git a/app/src/main/java/com/gh/gamecenter/db/DatabaseHelper.java b/app/src/main/java/com/gh/gamecenter/db/DatabaseHelper.java index 6a8f65d1c7..c21213e594 100644 --- a/app/src/main/java/com/gh/gamecenter/db/DatabaseHelper.java +++ b/app/src/main/java/com/gh/gamecenter/db/DatabaseHelper.java @@ -5,6 +5,7 @@ import android.database.sqlite.SQLiteDatabase; import android.support.v4.util.ArrayMap; import com.gh.gamecenter.db.info.AppTrafficInfo; +import com.gh.gamecenter.db.info.CollectionInfo; import com.lightgame.utils.Utils; import com.gh.gamecenter.db.info.AppRunTimeInfo; import com.gh.gamecenter.db.info.CommentInfo; @@ -30,7 +31,7 @@ import java.sql.SQLException; public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static final String DATABASE_NAME = "gh_assist.db"; - private static final int DATABASE_VERSION = 7; + private static final int DATABASE_VERSION = 8; private static DatabaseHelper instance; private ArrayMap daos = new ArrayMap<>(); @@ -75,6 +76,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTable(connectionSource, NoticeMarkReadInfo.class); TableUtils.createTable(connectionSource, VersionVoteInfo.class); TableUtils.createTable(connectionSource, AppTrafficInfo.class); + TableUtils.createTable(connectionSource, CollectionInfo.class); } catch (SQLException e) { e.printStackTrace(); } @@ -99,6 +101,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.dropTable(connectionSource, NoticeMarkReadInfo.class, true); TableUtils.dropTable(connectionSource, VersionVoteInfo.class, true); TableUtils.dropTable(connectionSource, AppTrafficInfo.class, true); + TableUtils.dropTable(connectionSource, CollectionInfo.class, true); onCreate(database, connectionSource); } catch (SQLException e) { e.printStackTrace(); diff --git a/app/src/main/java/com/gh/gamecenter/db/info/CollectionInfo.java b/app/src/main/java/com/gh/gamecenter/db/info/CollectionInfo.java new file mode 100644 index 0000000000..58b7fab066 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/db/info/CollectionInfo.java @@ -0,0 +1,34 @@ +package com.gh.gamecenter.db.info; + +import com.j256.ormlite.field.DatabaseField; +import com.j256.ormlite.table.DatabaseTable; + +import java.io.Serializable; + +/** + * Created by khy on 28/07/17. + * + * toolsId/acrticleID + */ +@DatabaseTable(tableName = "tb_collection") +public class CollectionInfo implements Serializable { + + @DatabaseField(id = true, columnName = "collectionId") + private String collectionId; + + public CollectionInfo() { + + } + + public CollectionInfo(String id) { + this.collectionId = id; + } + + public String getCollectionId() { + return collectionId; + } + + public void setCollectionId(String collectionId) { + this.collectionId = collectionId; + } +} diff --git a/app/src/main/java/com/gh/gamecenter/entity/ToolBoxEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/ToolBoxEntity.kt index e190e2d88f..dac3124137 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/ToolBoxEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/ToolBoxEntity.kt @@ -2,6 +2,7 @@ package com.gh.gamecenter.entity import android.os.Parcel import android.os.Parcelable +import com.google.gson.annotations.SerializedName /** * Created by khy on 24/05/17. @@ -9,6 +10,9 @@ import android.os.Parcelable class ToolBoxEntity : Parcelable { + @SerializedName(value = "_id", alternate = arrayOf("toolkit_id")) + var id: String? = null + var icon: String? = null var name: String? = null @@ -24,6 +28,7 @@ class ToolBoxEntity : Parcelable { } override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeString(this.id) dest.writeString(this.icon) dest.writeString(this.name) dest.writeString(this.des) @@ -34,6 +39,7 @@ class ToolBoxEntity : Parcelable { constructor() protected constructor(`in`: Parcel) { + this.id = `in`.readString() this.icon = `in`.readString() this.name = `in`.readString() this.des = `in`.readString() diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java index dbdac497df..42e6d821fa 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/ApiService.java @@ -24,9 +24,11 @@ import java.util.List; import okhttp3.RequestBody; import okhttp3.ResponseBody; import retrofit2.http.Body; +import retrofit2.http.DELETE; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; +import retrofit2.http.PATCH; import retrofit2.http.POST; import retrofit2.http.Path; import retrofit2.http.Query; @@ -206,4 +208,32 @@ public interface ApiService { @GET("toolkit") Observable> getToolBoxData(@Query("offset") int offset, @Query("key") String key, @Query("keyword") String keyword); + + @GET("toolkit") + Observable> getToolBoxById(@Query("id") String toolsId); + + @POST("favorite/toolkit") + Observable postCollectionTools(@Header("TOKEN") String token, @Body RequestBody body); // 增加收藏的工具 + + @POST("favorite/article") + Observable postCollectionArticle(@Header("TOKEN") String token, @Body RequestBody body); // 增加收藏的文章 + + @GET("favorite/toolkit") + Observable> getCollectionTools(@Header("TOKEN") String token, @Query("offset") int offset); // 获取收藏的工具 + + @GET("favorite/article") + Observable> getCollectionArticle(@Header("TOKEN") String token, @Query("offset") int offset); // 获取收藏的文章 + + @DELETE("favorite/toolkit/{toolsid}") + Observable deleteCollectionTools(@Header("TOKEN") String token, @Path("toolsid") String toolsId); // 删除收藏的文章 + + @DELETE("favorite/article/{articleid}") + Observable deletaCollectionArticle(@Header("TOKEN") String token, @Path("articleid") String articleId); // 删除收藏的工具 + + @PATCH("favorite/toolkit/{toolsid}") + Observable patchCollectionTools(@Header("TOKEN") String token, @Path("toolsid") String toolsId); // 修改收藏的文章 + + @PATCH("favorite/article/{articleid}") + Observable patchCollectionArticle(@Header("TOKEN") String token, @Path("articleid") String articleId); // 修改收藏的工具 + } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_news_detail.xml b/app/src/main/res/layout/activity_news_detail.xml index 0277158d43..c17e713e54 100644 --- a/app/src/main/res/layout/activity_news_detail.xml +++ b/app/src/main/res/layout/activity_news_detail.xml @@ -47,6 +47,7 @@ android:paddingLeft = "13dp" android:paddingRight = "13dp" android:paddingTop = "13dp" + android:visibility="gone" android:src = "@drawable/detail_collection_unselect" /> diff --git a/app/src/main/res/layout/fragment_article.xml b/app/src/main/res/layout/fragment_article.xml index 00dca94c7b..bc8d07b55f 100644 --- a/app/src/main/res/layout/fragment_article.xml +++ b/app/src/main/res/layout/fragment_article.xml @@ -3,8 +3,17 @@ android:layout_width = "match_parent" android:layout_height = "match_parent" > - + android:layout_height = "match_parent" > + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_tools.xml b/app/src/main/res/layout/fragment_tools.xml index 00dbfc813e..884c8dcdad 100644 --- a/app/src/main/res/layout/fragment_tools.xml +++ b/app/src/main/res/layout/fragment_tools.xml @@ -3,8 +3,17 @@ android:layout_width = "match_parent" android:layout_height = "match_parent" > - + android:layout_height = "match_parent" > + + + + + + \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 951ebc6262..80e52636a5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -40,7 +40,7 @@ UMENG_APPKEY=585a29fa8f4a9d327600023e UMENG_MESSAGE_SECRET=8bcce6bed547ee624f5c2cc64d39a9e9 # hosts -DEV_API_HOST=http\://dev.api.ghzs666.com/v2d6/ +DEV_API_HOST=http\://dev.api.ghzs666.com/v3d0/ DEV_DATA_HOST=http\://data.ghzs666.com/ DEV_LIBAO_HOST=http\://dev.libao.ghzs666.com/v1d2/ DEV_MESSAGE_HOST=http\://dev.message.ghzs666.com/v1d1/