增加收藏页面,优化登录流程
This commit is contained in:
@ -147,6 +147,12 @@ public class GetLoginDataUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public void QQLogout() {
|
||||
if (mTencent != null && mTencent.isSessionValid()) {
|
||||
mTencent.logout(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 微信登录
|
||||
public void WCLogin(OnLoginDataListener listener) {
|
||||
@ -159,6 +165,9 @@ public class GetLoginDataUtils {
|
||||
req.state = "光环助手";
|
||||
boolean b = mIWXAPI.sendReq(req);
|
||||
Utils.log(GetLoginDataUtils.class.getSimpleName(), "微信注册状态::" + register + "\n 发送状态::" + b);
|
||||
if (!register || !b) {
|
||||
Utils.toast(mContext, "请检查是否安装微信客户端");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -112,6 +112,14 @@ public class LoginUtils {
|
||||
@Override
|
||||
public void onResponse(LoginResponseEntity response) {
|
||||
super.onResponse(response);
|
||||
if (loginTag.equals(LoginTag.refresh)) {
|
||||
LoginResponseEntity loginToken = getLoginToken(context);
|
||||
if (loginToken != null) {
|
||||
response.setLoginType(loginToken.getLoginType());
|
||||
}
|
||||
} else {
|
||||
response.setLoginType(loginTag.name());
|
||||
}
|
||||
saveLoginToken(context, response);
|
||||
getUserData(context, response.getAccessToken().getValue(), listener);
|
||||
}
|
||||
@ -173,6 +181,8 @@ public class LoginUtils {
|
||||
edit.putString("user_info", null);
|
||||
edit.putString("login_token", null);
|
||||
edit.apply();
|
||||
|
||||
GetLoginDataUtils.getInstance(context).QQLogout();
|
||||
}
|
||||
|
||||
// 检查本地是否有缓存token,有则马上登录
|
||||
|
||||
35
app/src/main/java/com/gh/gamecenter/CollectionActivity.java
Normal file
35
app/src/main/java/com/gh/gamecenter/CollectionActivity.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.gamecenter.collection.CollectionFragment;
|
||||
|
||||
/**
|
||||
* Created by khy on 18/07/17.
|
||||
*/
|
||||
|
||||
public class CollectionActivity extends BaseActivity {
|
||||
|
||||
|
||||
public static final Intent getCollectionActivity(Context context) {
|
||||
Intent intent = new Intent(context, CollectionActivity.class);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_collection;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initTitle("我的收藏");
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(
|
||||
R.id.layout_fragment_content, CollectionFragment.newInstance(0)).commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,6 @@ import android.text.TextUtils;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
@ -87,8 +86,8 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
TextView mNoneDataTv;
|
||||
@BindView(R.id.news_detail_ll_coment)
|
||||
RelativeLayout mDetailCommentLl;
|
||||
|
||||
private ImageView iv_share;
|
||||
@BindView(R.id.news_detail_share)
|
||||
ImageView iv_share;
|
||||
|
||||
private NewsDetailAdapter adapter;
|
||||
|
||||
@ -218,21 +217,6 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
|
||||
initTitle("");
|
||||
|
||||
// 添加分享图标
|
||||
iv_share = new ImageView(this);
|
||||
iv_share.setImageResource(R.drawable.ic_share);
|
||||
iv_share.setOnClickListener(this);
|
||||
iv_share.setVisibility(View.GONE);
|
||||
iv_share.setPadding(DisplayUtils.dip2px(this, 13), DisplayUtils.dip2px(this, 11)
|
||||
, DisplayUtils.dip2px(this, 11), DisplayUtils.dip2px(this, 13));
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
DisplayUtils.dip2px(this, 48), ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
ViewGroup reuse_actionbar = (ViewGroup) mContentView.findViewById(
|
||||
R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(iv_share, params);
|
||||
|
||||
mDetailRv.setHasFixedSize(true);
|
||||
mDetailRv.setLayoutManager(new LinearLayoutManager(this));
|
||||
mDetailRv.addItemDecoration(new VerticalItemDecoration(this, 8, false));
|
||||
|
||||
@ -10,10 +10,12 @@ import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -21,6 +23,7 @@ import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.gamecenter.entity.LoginResponseEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.kyleduo.switchbutton.SwitchButton;
|
||||
@ -62,6 +65,10 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
TextView mSettingCacheTv;
|
||||
@BindView(R.id.setting_tv_size)
|
||||
TextView mSettingSizeTv;
|
||||
@BindView(R.id.setting_logout_tv)
|
||||
TextView mSettingLoginType;
|
||||
@BindView(R.id.setting_logout_rl)
|
||||
RelativeLayout mSettingLoginRl;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
@ -111,6 +118,17 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
checkSizeIndex = 1;
|
||||
}
|
||||
fontTextSize(checkSizeIndex);
|
||||
|
||||
LoginResponseEntity loginToken = LoginUtils.getLoginToken(this);
|
||||
if (loginToken != null) {
|
||||
String loginType = loginToken.getLoginType();
|
||||
if (!TextUtils.isEmpty(loginType)) {
|
||||
mSettingLoginType.setText(loginType);
|
||||
}
|
||||
mSettingLoginRl.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mSettingLoginRl.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -8,7 +8,6 @@ import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.DownloadListener;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
@ -40,7 +39,7 @@ import rx.schedulers.Schedulers;
|
||||
/**
|
||||
* Created by khy on 2016/10/18.
|
||||
*/
|
||||
public class WebActivity extends BaseActivity implements View.OnClickListener{
|
||||
public class WebActivity extends BaseActivity implements View.OnClickListener {
|
||||
|
||||
@BindView(R.id.news_webview)
|
||||
WebView webView;
|
||||
@ -52,8 +51,10 @@ public class WebActivity extends BaseActivity implements View.OnClickListener{
|
||||
RelativeLayout newsBottom;
|
||||
@BindView(R.id.actionbar_tv_title)
|
||||
TextView newsTitle;
|
||||
|
||||
private ImageView mShareIv;
|
||||
@BindView(R.id.web_share)
|
||||
ImageView mShareIv;
|
||||
@BindView(R.id.web_collection)
|
||||
ImageView mCollectionIv;
|
||||
|
||||
private String newsId;
|
||||
private int commentNum;
|
||||
@ -92,7 +93,7 @@ public class WebActivity extends BaseActivity implements View.OnClickListener{
|
||||
String webUrl;
|
||||
String webTitle;
|
||||
|
||||
mIsTools = getIntent().getBooleanExtra("isTools", false);
|
||||
mIsTools = getIntent().getBooleanExtra("isTools", false);
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
Bundle data = getIntent().getBundleExtra("data");
|
||||
webUrl = data.getString("url");
|
||||
@ -104,18 +105,11 @@ public class WebActivity extends BaseActivity implements View.OnClickListener{
|
||||
}
|
||||
|
||||
if (mIsTools) {
|
||||
mToolBoxEntity = getIntent().getParcelableExtra("ToolBoxEntity");
|
||||
mShareIv = new ImageView(this);
|
||||
mShareIv.setImageResource(R.drawable.menu_ic_share);
|
||||
mShareIv.setOnClickListener(this);
|
||||
mShareIv.setVisibility(View.VISIBLE);
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) mContentView.findViewById(
|
||||
R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(mShareIv, params);
|
||||
mCollectionIv.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mShareIv.setVisibility(View.GONE);
|
||||
mCollectionIv.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,274 @@
|
||||
package com.gh.gamecenter.collection;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
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.NewsUtils;
|
||||
import com.gh.gamecenter.NewsDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
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.manager.VisitManager;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.lightgame.adapter.BaseRecyclerAdapter;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by khy on 18/07/17.
|
||||
*/
|
||||
|
||||
public class ArticleAdapter extends BaseRecyclerAdapter {
|
||||
|
||||
private List<NewsEntity> mNewsList;
|
||||
|
||||
|
||||
public ArticleAdapter(Context context) {
|
||||
super(context);
|
||||
mNewsList = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == mNewsList.size()) {
|
||||
return ItemViewType.LOADING;
|
||||
}
|
||||
NewsEntity newsEntity = mNewsList.get(position);
|
||||
if ("4x3".equals(newsEntity.getThumbnail().getType()) && newsEntity.getThumbnail().getUrl().size() == 3) {
|
||||
return ItemViewType.NEWS_IMAGE2;
|
||||
}
|
||||
if ("3x1".equals(newsEntity.getThumbnail().getType())) {
|
||||
return ItemViewType.NEWS_IMAGE3;
|
||||
}
|
||||
return ItemViewType.NEWS_IMAGE1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
switch (viewType) {
|
||||
case ItemViewType.NEWS_IMAGE1:
|
||||
return new NewsImage1ViewHolder(mLayoutInflater.inflate(R.layout.news_image1_item, parent, false));
|
||||
case ItemViewType.NEWS_IMAGE2:
|
||||
return new NewsImage2ViewHolder(mLayoutInflater.inflate(R.layout.news_image2_item, parent, false));
|
||||
case ItemViewType.NEWS_IMAGE3:
|
||||
return new NewsImage3ViewHolder(mLayoutInflater.inflate(R.layout.news_image3_item, parent, false));
|
||||
case ItemViewType.LOADING:
|
||||
return new FooterViewHolder(mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
switch (getItemViewType(position)) {
|
||||
case ItemViewType.NEWS_IMAGE1:
|
||||
initNewsImage1ViewHolder((NewsImage1ViewHolder) holder, position);
|
||||
break;
|
||||
case ItemViewType.NEWS_IMAGE2:
|
||||
initNewsImage2ViewHolder((NewsImage2ViewHolder) holder, position);
|
||||
break;
|
||||
case ItemViewType.NEWS_IMAGE3:
|
||||
initNewsImage3ViewHolder((NewsImage3ViewHolder) holder, position);
|
||||
break;
|
||||
case ItemViewType.LOADING:
|
||||
initFooterViewHolder((FooterViewHolder) holder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mNewsList.size() + 1;
|
||||
}
|
||||
|
||||
private void initNewsImage1ViewHolder(final NewsImage1ViewHolder viewHolder, int position) {
|
||||
|
||||
final NewsEntity newsEntity = mNewsList.get(position);
|
||||
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("名字", newsEntity.getTitle());
|
||||
kv.put("位置", String.valueOf(viewHolder.getPosition() + 1));
|
||||
DataUtils.onEvent(mContext, "点击", "资讯-资讯", kv);
|
||||
|
||||
DataCollectionUtils.uploadClick(mContext, "列表", "资讯-资讯", newsEntity.getTitle());
|
||||
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity, viewHolder.getPosition());
|
||||
NewsDetailActivity.startNewsDetailActivity(mContext, newsEntity, "(资讯:资讯[2-1])");
|
||||
}
|
||||
});
|
||||
ImageUtils.Companion.display(viewHolder.thumb, newsEntity.getThumbnail().getUrl().get(0));
|
||||
viewHolder.title.setText(newsEntity.getTitle());
|
||||
int views = newsEntity.getViews();
|
||||
if (views == 0) {
|
||||
viewHolder.read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.read.setVisibility(View.VISIBLE);
|
||||
viewHolder.read.setText(String.format(Locale.getDefault(), "阅读 %d", views));
|
||||
}
|
||||
NewsUtils.setNewsType(viewHolder.type, newsEntity.getType(), newsEntity.getPriority(), position);
|
||||
}
|
||||
|
||||
private void initNewsImage2ViewHolder(final NewsImage2ViewHolder viewHolder, int position) {
|
||||
|
||||
final NewsEntity newsEntity = mNewsList.get(position);
|
||||
|
||||
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getMetrics(outMetrics);
|
||||
int width = (outMetrics.widthPixels - DisplayUtils.dip2px(mContext, 56)) / 3;
|
||||
int height = (int) (width * 3 / 4f);
|
||||
|
||||
LinearLayout.LayoutParams lparams1 = new LinearLayout.LayoutParams(width, height);
|
||||
viewHolder.thumb1.setLayoutParams(lparams1);
|
||||
|
||||
LinearLayout.LayoutParams lparams2 = new LinearLayout.LayoutParams(width, height);
|
||||
lparams2.leftMargin = DisplayUtils.dip2px(mContext, 8);
|
||||
viewHolder.thumb2.setLayoutParams(lparams2);
|
||||
|
||||
LinearLayout.LayoutParams lparams3 = new LinearLayout.LayoutParams(width, height);
|
||||
lparams3.leftMargin = DisplayUtils.dip2px(mContext, 8);
|
||||
viewHolder.thumb3.setLayoutParams(lparams3);
|
||||
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("名字", newsEntity.getTitle());
|
||||
kv.put("位置", String.valueOf(viewHolder.getPosition() + 1));
|
||||
DataUtils.onEvent(mContext, "点击", "资讯-资讯", kv);
|
||||
|
||||
DataCollectionUtils.uploadClick(mContext, "列表", "资讯-资讯", newsEntity.getTitle());
|
||||
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity, viewHolder.getPosition());
|
||||
NewsDetailActivity.startNewsDetailActivity(mContext, newsEntity, "(资讯:资讯[2-1])");
|
||||
}
|
||||
});
|
||||
viewHolder.title.setText(newsEntity.getTitle());
|
||||
ImageUtils.Companion.display(viewHolder.thumb1, newsEntity.getThumbnail().getUrl().get(0));
|
||||
ImageUtils.Companion.display(viewHolder.thumb2, newsEntity.getThumbnail().getUrl().get(1));
|
||||
ImageUtils.Companion.display(viewHolder.thumb3, newsEntity.getThumbnail().getUrl().get(2));
|
||||
int views = newsEntity.getViews();
|
||||
if (views == 0) {
|
||||
viewHolder.read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.read.setVisibility(View.VISIBLE);
|
||||
viewHolder.read.setText(String.format(Locale.getDefault(), "阅读 %d", views));
|
||||
}
|
||||
NewsUtils.setNewsType(viewHolder.type, newsEntity.getType(), newsEntity.getPriority(), position);
|
||||
}
|
||||
|
||||
private void initNewsImage3ViewHolder(final NewsImage3ViewHolder viewHolder, int position) {
|
||||
|
||||
final NewsEntity newsEntity = mNewsList.get(position);
|
||||
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("名字", newsEntity.getTitle());
|
||||
kv.put("位置", String.valueOf(viewHolder.getPosition() + 1));
|
||||
DataUtils.onEvent(mContext, "点击", "资讯-资讯", kv);
|
||||
|
||||
DataCollectionUtils.uploadClick(mContext, "列表", "资讯-资讯", newsEntity.getTitle());
|
||||
|
||||
//统计阅读量
|
||||
statNewsViews(newsEntity, viewHolder.getPosition());
|
||||
NewsDetailActivity.startNewsDetailActivity(mContext, newsEntity, "(资讯:资讯[2-1])");
|
||||
}
|
||||
});
|
||||
viewHolder.title.setText(newsEntity.getTitle());
|
||||
ImageUtils.Companion.getInstance().display(viewHolder.thumb, newsEntity.getThumbnail().getUrl().get(0),
|
||||
mContext.getResources().getDisplayMetrics().widthPixels - DisplayUtils.dip2px(mContext, 40));
|
||||
int views = newsEntity.getViews();
|
||||
if (views == 0) {
|
||||
viewHolder.read.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewHolder.read.setVisibility(View.VISIBLE);
|
||||
viewHolder.read.setText(String.format(Locale.getDefault(), "阅读 %d", views));
|
||||
}
|
||||
NewsUtils.setNewsType(viewHolder.type, newsEntity.getType(), newsEntity.getPriority(), position);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
// }
|
||||
}
|
||||
|
||||
// 统计新闻阅读量
|
||||
private void statNewsViews(final NewsEntity newsEntity, final int position) {
|
||||
RetrofitManager.getData().postNewsViews(newsEntity.getId())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
try {
|
||||
if ("success".equals(response.getString("status"))) {
|
||||
newsEntity.setViews(newsEntity.getViews() + 1);
|
||||
|
||||
notifyItemChanged(position);
|
||||
|
||||
// 更新okhttp缓存数据
|
||||
VisitManager.updateOkhttpCache(newsEntity.getId());
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.gh.gamecenter.collection;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.gh.base.fragment.BaseFragment;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 18/07/17.
|
||||
*/
|
||||
|
||||
public class ArticleFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.article_rv)
|
||||
RecyclerView mRecyclerView;
|
||||
|
||||
private ArticleAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_article;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
mAdapter = new ArticleAdapter(getContext());
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
package com.gh.gamecenter.collection;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gh.base.fragment.BaseFragment_ViewPager_Checkable;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 18/07/17.
|
||||
*/
|
||||
|
||||
public class CollectionFragment extends BaseFragment_ViewPager_Checkable {
|
||||
|
||||
@BindView(R.id.slidebar_line)
|
||||
View mSlideLine;
|
||||
|
||||
private LinearLayout.LayoutParams mLayoutParams;
|
||||
private int mWindowWidth;
|
||||
|
||||
public static CollectionFragment newInstance(int checkedIndex) {
|
||||
final Bundle args = new Bundle(1);
|
||||
args.putInt(ARGS_INDEX, checkedIndex);
|
||||
final CollectionFragment fragment = new CollectionFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean getSmoothScroll() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCheckableGroupId() {
|
||||
return R.id.lightgame_tab_container;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_collection;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getViewPagerId() {
|
||||
return R.id.lightgame_tab_viewpager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initFragmentList(List<Fragment> fragments) {
|
||||
fragments.add(new ArticleFragment());
|
||||
fragments.add(new ToolsFragment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
mWindowWidth = outMetrics.widthPixels / 2;
|
||||
mLayoutParams = new LinearLayout.LayoutParams((int) (mWindowWidth * 0.6), DisplayUtils.dip2px(getContext(), 2));
|
||||
mLayoutParams.leftMargin = (int) (mWindowWidth * (0 + 0.2f));
|
||||
mSlideLine.setLayoutParams(mLayoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
super.onPageScrolled(position, positionOffset, positionOffsetPixels);
|
||||
if (positionOffset != 0) {
|
||||
mLayoutParams.leftMargin = (int) (mWindowWidth * (position + positionOffset + 0.17f));
|
||||
mSlideLine.setLayoutParams(mLayoutParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
100
app/src/main/java/com/gh/gamecenter/collection/ToolsAdapter.java
Normal file
100
app/src/main/java/com/gh/gamecenter/collection/ToolsAdapter.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.gh.gamecenter.collection;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
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.lightgame.adapter.BaseRecyclerAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 18/07/17.
|
||||
*/
|
||||
|
||||
public class ToolsAdapter extends BaseRecyclerAdapter {
|
||||
|
||||
private List<ToolBoxEntity> mEntityList;
|
||||
|
||||
public ToolsAdapter(Context context) {
|
||||
super(context);
|
||||
mEntityList = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == getItemCount() - 1) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == 0) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.toolbox_item, parent, false);
|
||||
return new ToolBoxViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof ToolBoxViewHolder) {
|
||||
ToolBoxViewHolder viewHolder = (ToolBoxViewHolder) holder;
|
||||
ToolBoxEntity toolBoxEntity = mEntityList.get(position - 2);
|
||||
initToolsViewHolder(viewHolder, toolBoxEntity);
|
||||
} else if (holder instanceof FooterViewHolder) {
|
||||
FooterViewHolder viewHolder = (FooterViewHolder) holder;
|
||||
// initFooterViewHolder(viewHolder, position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mEntityList.size() + 1;
|
||||
}
|
||||
|
||||
private void initToolsViewHolder(ToolBoxViewHolder viewHolder, final ToolBoxEntity toolBoxEntity) {
|
||||
viewHolder.mDes.setText(toolBoxEntity.getDes());
|
||||
viewHolder.mTitle.setText(toolBoxEntity.getName());
|
||||
ImageUtils.Companion.display(viewHolder.mGameThumb, toolBoxEntity.getIcon());
|
||||
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
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, "工具箱列表");
|
||||
mContext.startActivity(intent);
|
||||
} else {
|
||||
AppController.put("ToolBoxEntity", toolBoxEntity);
|
||||
Intent intent = new Intent(mContext, WebActivity.class);
|
||||
intent.putExtra("url", toolBoxEntity.getUrl());
|
||||
intent.putExtra("isTools", true);
|
||||
intent.putExtra("gameName", toolBoxEntity.getName());
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.gh.gamecenter.collection;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.gh.base.fragment.BaseFragment;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 18/07/17.
|
||||
*/
|
||||
|
||||
public class ToolsFragment extends BaseFragment {
|
||||
|
||||
@BindView(R.id.tools_rv)
|
||||
RecyclerView mRecyclerView;
|
||||
|
||||
private ToolsAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_tools;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
mAdapter = new ToolsAdapter(getContext());
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,8 @@ class LoginResponseEntity {
|
||||
@SerializedName("refresh_token")
|
||||
var refreshToken: RefreshToken? = null
|
||||
|
||||
var loginType: String? = null;
|
||||
|
||||
class AccessToken {
|
||||
var value: String? = null
|
||||
var expire: Long? = null
|
||||
|
||||
@ -19,7 +19,7 @@ public class NewsDetailContentViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public NewsDetailContentViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
itemView.requestFocus();
|
||||
newsdetail_item_tv_title = (TextView) itemView.findViewById(R.id.newsdetail_item_tv_title);
|
||||
newsdetail_item_tv_time = (TextView) itemView.findViewById(R.id.newsdetail_item_tv_time);
|
||||
newsdetail_item_tv_author = (TextView) itemView.findViewById(R.id.newsdetail_item_tv_author);
|
||||
|
||||
@ -18,6 +18,7 @@ import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.GetLoginDataUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.gamecenter.CollectionActivity;
|
||||
import com.gh.gamecenter.InstallActivity;
|
||||
import com.gh.gamecenter.LibaoActivity;
|
||||
import com.gh.gamecenter.LoginActivity;
|
||||
@ -100,6 +101,9 @@ public class PersonalFragment extends BaseFragment implements GetLoginDataUtils.
|
||||
public final static String LOGIN_TAG = "login_tag"; //登入标识
|
||||
public final static String LOGOUT_TAG = "logout_tag"; // 登出标识
|
||||
|
||||
public final static int CHANGE_UDERINFO = 0x310; // 登出标识
|
||||
|
||||
|
||||
private UserInfoEntity mUserInfoEntity;
|
||||
|
||||
@Override
|
||||
@ -124,6 +128,9 @@ public class PersonalFragment extends BaseFragment implements GetLoginDataUtils.
|
||||
changeLoginState(false);
|
||||
mUserInfoEntity = null;
|
||||
}
|
||||
} else if (requestCode == CHANGE_UDERINFO) {
|
||||
mUserInfoEntity = LoginUtils.getUserInfo(getContext());
|
||||
changeLoginState(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,11 +159,12 @@ public class PersonalFragment extends BaseFragment implements GetLoginDataUtils.
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.personal_login_qq:
|
||||
if (mUserInfoEntity != null) {
|
||||
toast("收藏");
|
||||
} else {
|
||||
GetLoginDataUtils.getInstance(getActivity()).QQLogin(this, getActivity());
|
||||
}
|
||||
startActivity(CollectionActivity.getCollectionActivity(getContext()));
|
||||
// if (mUserInfoEntity != null) {
|
||||
//
|
||||
// } else {
|
||||
// GetLoginDataUtils.getInstance(getActivity()).QQLogin(this, getActivity());
|
||||
// }
|
||||
break;
|
||||
case R.id.personal_login_wechat:
|
||||
if (mUserInfoEntity != null) {
|
||||
@ -175,7 +183,7 @@ public class PersonalFragment extends BaseFragment implements GetLoginDataUtils.
|
||||
case R.id.personal_user_icon:
|
||||
case R.id.personal_user_name:
|
||||
if (mUserInfoEntity != null) {
|
||||
getContext().startActivity(UserInfoActivity.getIntent(getContext()));
|
||||
startActivityForResult(UserInfoActivity.getIntent(getContext()), CHANGE_UDERINFO);
|
||||
} else {
|
||||
startActivityForResult(LoginActivity.getIntent(getContext()), LOGIN_CODE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user