391 lines
16 KiB
Java
391 lines
16 KiB
Java
package com.gh.gamecenter.personal;
|
|
|
|
import android.app.Dialog;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.SharedPreferences;
|
|
import android.os.Bundle;
|
|
import android.preference.PreferenceManager;
|
|
import android.support.annotation.Nullable;
|
|
import android.view.View;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
|
|
import com.facebook.drawee.view.SimpleDraweeView;
|
|
import com.gh.base.fragment.BaseFragment;
|
|
import com.gh.common.util.DataCollectionUtils;
|
|
import com.gh.gamecenter.DataUtils;
|
|
import com.gh.common.util.DialogUtils;
|
|
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;
|
|
import com.gh.gamecenter.MessageActivity;
|
|
import com.gh.gamecenter.R;
|
|
import com.gh.gamecenter.ShareGhActivity;
|
|
import com.gh.gamecenter.SuggestSelectActivity;
|
|
import com.gh.gamecenter.SuggestionActivity;
|
|
import com.gh.gamecenter.UserInfoActivity;
|
|
import com.gh.gamecenter.entity.AppEntity;
|
|
import com.gh.gamecenter.entity.LoginResponseEntity;
|
|
import com.gh.gamecenter.entity.MessageUnreadEntity;
|
|
import com.gh.gamecenter.entity.UserInfoEntity;
|
|
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
|
import com.gh.gamecenter.eventbus.EBNetworkState;
|
|
import com.gh.gamecenter.eventbus.EBReuse;
|
|
import com.gh.gamecenter.message.MessageFragment;
|
|
import com.gh.gamecenter.retrofit.Response;
|
|
import com.gh.gamecenter.retrofit.RetrofitManager;
|
|
import com.halo.assistant.HaloApp;
|
|
import com.halo.assistant.ui.IntentFactory;
|
|
import com.halo.assistant.fragment.SettingsFragment;
|
|
import com.lightgame.config.CommonDebug;
|
|
import com.lightgame.utils.Utils;
|
|
import com.tencent.connect.common.Constants;
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
import org.json.JSONObject;
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.OnClick;
|
|
import retrofit2.HttpException;
|
|
import rx.android.schedulers.AndroidSchedulers;
|
|
import rx.schedulers.Schedulers;
|
|
|
|
/**
|
|
* @author 温冠超
|
|
* 294299195@qq.com
|
|
* 2015-8-8 我的光环页面
|
|
*/
|
|
public class PersonalFragment extends BaseFragment implements GetLoginDataUtils.OnLoginDataListener,
|
|
LoginUtils.onLoginCallBackListener {
|
|
|
|
@BindView(R.id.personal_login_qq)
|
|
LinearLayout mLoginQq;
|
|
@BindView(R.id.personal_login_wechat)
|
|
LinearLayout mLoginWechat;
|
|
@BindView(R.id.personal_login_weibo)
|
|
LinearLayout mLoginWeibo;
|
|
@BindView(R.id.personal_user_icon)
|
|
SimpleDraweeView mUserIcon;
|
|
@BindView(R.id.personal_user_name)
|
|
TextView mUserName;
|
|
@BindView(R.id.login_qq_icon)
|
|
ImageView mLoginQqIcon;
|
|
@BindView(R.id.login_qq_tv)
|
|
TextView mLoginQqTv;
|
|
@BindView(R.id.login_wechat_icon)
|
|
ImageView mLoginWechatIcon;
|
|
@BindView(R.id.login_wechat_tv)
|
|
TextView mLoginWechatTv;
|
|
@BindView(R.id.login_weibo_icon)
|
|
ImageView mLoginWeiboIcon;
|
|
@BindView(R.id.login_weibo_tv)
|
|
TextView mLoginWeiboTv;
|
|
@BindView(R.id.personal_game)
|
|
RelativeLayout mPersonalGame;
|
|
@BindView(R.id.personal_libao)
|
|
RelativeLayout mPersonalLibao;
|
|
@BindView(R.id.personal_share)
|
|
RelativeLayout mPersonalShare;
|
|
@BindView(R.id.personal_suggestion)
|
|
RelativeLayout mPersonalSuggestion;
|
|
@BindView(R.id.personal_setting_update_hint)
|
|
TextView mPersonalSettingUpdateHint;
|
|
@BindView(R.id.personal_setting)
|
|
RelativeLayout mPersonalSetting;
|
|
@BindView(R.id.login_sign_hint)
|
|
View mLoginSignHint;
|
|
@BindView(R.id.login_message_hint)
|
|
View mLoginMessgeHint;
|
|
@BindView(R.id.user_icon_hint)
|
|
View mIconHint;
|
|
|
|
public final static int LOGIN_CODE = 0x300; // 登录相关的requestCode && resultCode
|
|
public final static int CHANGE_UDERINFO = 0x310; // 登出标识
|
|
|
|
public final static String LOGIN_TAG = "login_tag"; //登入标识
|
|
public final static String LOGOUT_TAG = "logout_tag"; // 登出标识
|
|
public final static String MESSAGE_UNREAD_TAG = "message_unread_tag";
|
|
|
|
private UserInfoEntity mUserInfoEntity;
|
|
|
|
private Dialog mLoginDialog;
|
|
|
|
private SharedPreferences sp;
|
|
|
|
@Override
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
if (CommonDebug.IS_DEBUG) {
|
|
CommonDebug.logMethodWithParams(this, requestCode, resultCode, data);
|
|
}
|
|
|
|
if (requestCode == Constants.REQUEST_LOGIN) { // QQ Login callback
|
|
GetLoginDataUtils.getInstance(getContext()).onQQCallback(requestCode, resultCode, data);
|
|
} else if (requestCode == 32973) {// 32973 WeiBo requestCode
|
|
|
|
GetLoginDataUtils.getInstance(getContext()).onWeiboCallback(requestCode, resultCode, data);
|
|
} else if (requestCode == CHANGE_UDERINFO) {
|
|
mUserInfoEntity = LoginUtils.getUserInfo(getContext());
|
|
changeLoginState(true);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.fragment_personal;
|
|
}
|
|
|
|
@Override
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
checkUpdate();
|
|
|
|
LoginUtils.checkLogin(getContext(), this);
|
|
}
|
|
|
|
|
|
// 连接上网络事件
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void onEventMainThread(EBNetworkState busNetworkState) {
|
|
if (busNetworkState.isNetworkConnected() && mUserInfoEntity == null) {
|
|
LoginResponseEntity loginToken = LoginUtils.getLoginToken(getContext());
|
|
if (loginToken != null)
|
|
LoginUtils.checkLogin(getContext(), this);
|
|
}
|
|
}
|
|
|
|
// 登录事件
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void onEventMainThread(EBReuse reuse) {
|
|
switch (reuse.getType()) {
|
|
case LOGIN_TAG: // 登入
|
|
mUserInfoEntity = LoginUtils.getUserInfo(getContext());
|
|
changeLoginState(true);
|
|
checkMessageUnread(getContext()); // 检查是否有未读消息
|
|
|
|
EventBus.getDefault().post(new EBConcernChanged());
|
|
|
|
/**
|
|
* default_icon_ 判断是不是默认头像
|
|
* 具体默认头像链接请看:
|
|
* {@link com.gh.common.util.UserIconUtils#getUserIconUrl(int)}
|
|
*/
|
|
LoginResponseEntity loginToken = LoginUtils.getLoginToken(getContext());
|
|
if (loginToken != null &&
|
|
loginToken.getUserToken() != null &&
|
|
sp.getBoolean(loginToken.getUserToken(), true) &&
|
|
mUserInfoEntity.getIcon() != null &&
|
|
mUserInfoEntity.getIcon().contains("default_icon_")) {
|
|
mIconHint.setVisibility(View.VISIBLE);
|
|
}
|
|
break;
|
|
case LOGOUT_TAG: // 登出
|
|
changeLoginState(false);
|
|
mUserInfoEntity = null;
|
|
EventBus.getDefault().post(new EBConcernChanged());
|
|
|
|
if (mIconHint.getVisibility() == View.VISIBLE) mIconHint.setVisibility(View.GONE);
|
|
break;
|
|
case MessageFragment.MESSAGE_READ_OVER: // 消息阅读完成
|
|
if (mLoginMessgeHint != null) {
|
|
mLoginMessgeHint.setVisibility(View.GONE);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
@OnClick({R.id.personal_login_qq, R.id.personal_login_wechat, R.id.personal_login_weibo, R.id.personal_user_icon,
|
|
R.id.personal_user_name, R.id.personal_game, R.id.personal_libao, R.id.personal_share, R.id.personal_suggestion,
|
|
R.id.personal_setting})
|
|
public void onViewClicked(View view) {
|
|
switch (view.getId()) {
|
|
case R.id.personal_login_qq:
|
|
if (mUserInfoEntity != null) {
|
|
startActivity(CollectionActivity.getCollectionActivity(getContext()));
|
|
} else {
|
|
GetLoginDataUtils.getInstance(getActivity()).QQLogin(this, getActivity());
|
|
}
|
|
break;
|
|
case R.id.personal_login_wechat:
|
|
if (mUserInfoEntity != null) {
|
|
|
|
DialogUtils.showAlertDialog(getContext(), "期待你的建议", "签到功能暂未开放,如果你有好的建议请反馈给我们,谢谢!"
|
|
, "我有一个想法", " 以后再说", new DialogUtils.ConfirmListener() {
|
|
@Override
|
|
public void onConfirm() {
|
|
SuggestionActivity.startSuggestionActivity(getContext(), 2, null, "签到功能的建议:");
|
|
}
|
|
});
|
|
} else {
|
|
GetLoginDataUtils.getInstance(getActivity()).WCLogin(this);
|
|
}
|
|
break;
|
|
case R.id.personal_login_weibo:
|
|
if (mUserInfoEntity != null) {
|
|
startActivity(MessageActivity.getIntent(getContext()));
|
|
} else {
|
|
GetLoginDataUtils.getInstance(getActivity()).WeiBoLogin(this, getActivity());
|
|
}
|
|
break;
|
|
case R.id.personal_user_icon:
|
|
case R.id.personal_user_name:
|
|
|
|
if (mIconHint.getVisibility() == View.VISIBLE) {
|
|
LoginResponseEntity loginToken = LoginUtils.getLoginToken(getContext());
|
|
mIconHint.setVisibility(View.GONE);
|
|
if (loginToken != null && loginToken.getUserToken() != null)
|
|
sp.edit().putBoolean(loginToken.getUserToken(), false).apply();
|
|
}
|
|
|
|
if (mUserInfoEntity != null) {
|
|
startActivityForResult(UserInfoActivity.getIntent(getContext()), CHANGE_UDERINFO);
|
|
} else {
|
|
startActivityForResult(LoginActivity.getIntent(getContext(), false), LOGIN_CODE);
|
|
}
|
|
break;
|
|
case R.id.personal_game:
|
|
getContext().startActivity(InstallActivity.getIntent(getContext()));
|
|
break;
|
|
case R.id.personal_libao:
|
|
DataUtils.onEvent(getActivity(), "主页", "礼包图标");
|
|
DataCollectionUtils.uploadClick(getActivity(), "礼包图标", "我的光环");
|
|
Intent intent = LibaoActivity.getIntent(getContext(), "(我的光环:礼包[4-1])");
|
|
startActivity(intent);
|
|
|
|
DataCollectionUtils.uploadPosition(getActivity(), "我的光环", "1", "礼包");
|
|
break;
|
|
case R.id.personal_share:
|
|
getContext().startActivity(ShareGhActivity.getIntent(getContext()));
|
|
break;
|
|
case R.id.personal_suggestion:
|
|
getContext().startActivity(SuggestSelectActivity.getIntent(getActivity()));
|
|
break;
|
|
case R.id.personal_setting:
|
|
DataUtils.onEvent(getActivity(), "我的光环", "设置图标");
|
|
DataCollectionUtils.uploadClick(getActivity(), "设置图标", "我的光环");
|
|
|
|
new IntentFactory.Builder(getContext()).setFragment(SettingsFragment.class).setEntrance("(我的光环)").start();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void checkMessageUnread(final Context context) {
|
|
if (context == null) return;
|
|
|
|
RetrofitManager.getInstance(context).getApi()
|
|
.getMessageUnread()
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new Response<MessageUnreadEntity>() {
|
|
@Override
|
|
public void onResponse(MessageUnreadEntity response) {
|
|
super.onResponse(response);
|
|
if (response != null && response.getKefuList() != null && response.getKefuList().size() > 0) {
|
|
if (response.getKefuList() != null && response.getKefuList().size() > 0) {
|
|
mLoginMessgeHint.setVisibility(View.VISIBLE);
|
|
}
|
|
}
|
|
|
|
if (response != null && response.getComment() > 0) {
|
|
mLoginMessgeHint.setVisibility(View.VISIBLE);
|
|
}
|
|
|
|
if (mLoginMessgeHint.getVisibility() == View.VISIBLE) {
|
|
EventBus.getDefault().post(new EBReuse(MESSAGE_UNREAD_TAG));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(HttpException e) {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
private void changeLoginState(boolean isLogin) {
|
|
if (isLogin) {
|
|
if (mUserInfoEntity != null) {
|
|
mUserIcon.setImageURI(mUserInfoEntity.getIcon());
|
|
mUserName.setText(mUserInfoEntity.getName());
|
|
}
|
|
mLoginQqIcon.setImageResource(R.drawable.personal_collection_icon);
|
|
mLoginQqTv.setText("收藏");
|
|
mLoginWechatIcon.setImageResource(R.drawable.personal_sign_icon);
|
|
mLoginWechatTv.setText("签到");
|
|
mLoginWeiboIcon.setImageResource(R.drawable.personal_message_icon);
|
|
mLoginWeiboTv.setText("消息");
|
|
} else {
|
|
mLoginQqIcon.setImageResource(R.drawable.qq_login_icon);
|
|
mLoginQqTv.setText(getString(R.string.QQ));
|
|
mLoginWechatIcon.setImageResource(R.drawable.wechat_login_icon);
|
|
mLoginWechatTv.setText(getString(R.string.wechat));
|
|
mLoginWeiboIcon.setImageResource(R.drawable.weibo_login_icon);
|
|
mLoginWeiboTv.setText(getString(R.string.sina_weibo));
|
|
mLoginSignHint.setVisibility(View.GONE);
|
|
mLoginMessgeHint.setVisibility(View.GONE);
|
|
mUserIcon.setImageURI("");
|
|
mUserName.setText("手机登录");
|
|
}
|
|
}
|
|
|
|
private void checkUpdate() {
|
|
String channel = HaloApp.getInstance().getChannel();
|
|
RetrofitManager.getInstance(getContext())
|
|
.getApi()
|
|
.getUpdate(PackageUtils.getVersionName(getContext()), channel)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new Response<AppEntity>() {
|
|
@Override
|
|
public void onResponse(AppEntity response) {
|
|
super.onResponse(response);
|
|
float version = Float.valueOf(response.getVersion());
|
|
float currentVersion = Float.valueOf(PackageUtils.getVersionName(getContext()));
|
|
if (version > currentVersion) {
|
|
mPersonalSettingUpdateHint.setVisibility(View.VISIBLE);
|
|
} else {
|
|
mPersonalSettingUpdateHint.setVisibility(View.GONE);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
// 登录成功返回
|
|
@Override
|
|
public void OnLoginData(JSONObject content, LoginUtils.LoginTag loginTag) {
|
|
Utils.log("======获取第三方登录信息成功" + content.toString() + "===" + loginTag.name());
|
|
mLoginDialog = DialogUtils.showWaitDialog(getContext(), "登录中...");
|
|
LoginUtils.login(getContext(), content, loginTag, this);
|
|
}
|
|
|
|
@Override
|
|
public void onLogin(UserInfoEntity entity, LoginUtils.LoginTag loginTag) {
|
|
Utils.log("======登录成功" + entity.getIcon() + "==" + entity.getName() + "==" + loginTag);
|
|
EventBus.getDefault().post(new EBReuse(PersonalFragment.LOGIN_TAG));
|
|
if (mLoginDialog != null) {
|
|
mLoginDialog.dismiss();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onLoginFailure() {
|
|
if (mLoginDialog != null) {
|
|
mLoginDialog.dismiss();
|
|
}
|
|
}
|
|
|
|
}
|