package com.weikou.beibeivideo.ui.main;
|
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.content.SharedPreferences.Editor;
|
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.database.Cursor;
|
import android.os.Bundle;
|
|
import androidx.loader.app.LoaderManager;
|
import androidx.loader.content.CursorLoader;
|
import androidx.loader.content.Loader;
|
|
import android.util.Log;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.view.ViewGroup;
|
import android.webkit.WebChromeClient;
|
import android.webkit.WebViewClient;
|
import android.widget.BaseAdapter;
|
import android.widget.GridView;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.RelativeLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.alibaba.baichuan.android.trade.AlibcTradeSDK;
|
import com.alibaba.baichuan.android.trade.model.AlibcShowParams;
|
import com.alibaba.baichuan.android.trade.model.OpenType;
|
import com.alibaba.baichuan.trade.biz.applink.adapter.AlibcFailModeType;
|
import com.alibaba.baichuan.trade.biz.core.taoke.AlibcTaokeParams;
|
import com.alibaba.fastjson.JSONObject;
|
import com.androidquery.AQuery;
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
import com.bumptech.glide.request.RequestOptions;
|
import com.lcjian.library.content.ConnectivityChangeHelper;
|
import com.lcjian.library.content.ConnectivityChangeHelper.OnConnectivityChangeListener;
|
import com.lcjian.library.util.common.DimenUtils;
|
import com.lcjian.library.util.common.StringUtils;
|
import com.lcjian.library.util.glide.GlideRoundTransform;
|
import com.lcjian.library.widget.RatioLayout;
|
import com.umeng.analytics.MobclickAgent;
|
import com.umeng.socialize.UMShareAPI;
|
import com.umeng.socialize.UMShareListener;
|
import com.umeng.socialize.bean.SHARE_MEDIA;
|
import com.video.youth.ui.YouthActivity;
|
import com.video.youth.util.YouthUtil;
|
import com.weikou.beibeivideo.R;
|
import com.weikou.beibeivideo.db.MessageTable;
|
import com.weikou.beibeivideo.entity.NewComment;
|
import com.weikou.beibeivideo.entity.UserInfo;
|
import com.weikou.beibeivideo.entity.vo.BannerVO;
|
import com.weikou.beibeivideo.entity.vo.UserInfoVO;
|
import com.weikou.beibeivideo.ui.MyRetainViewFragment;
|
import com.weikou.beibeivideo.ui.common.FollowActivity;
|
import com.weikou.beibeivideo.ui.dialog.ShareAPPDialog;
|
import com.weikou.beibeivideo.ui.login.LoginActivity;
|
import com.weikou.beibeivideo.ui.login.PersonInfoActivity;
|
import com.weikou.beibeivideo.ui.mine.BrowserActivity;
|
import com.weikou.beibeivideo.ui.mine.GoldCornActivity;
|
import com.weikou.beibeivideo.ui.mine.HelpAndTicklingActivity;
|
import com.weikou.beibeivideo.ui.mine.MyFavouriteActivity;
|
import com.weikou.beibeivideo.ui.mine.SettingsActivity;
|
import com.weikou.beibeivideo.ui.mine.SystemMessageActivity;
|
import com.weikou.beibeivideo.ui.mine.WatchHistoryActivity;
|
import com.weikou.beibeivideo.ui.recommend.SearchActivity;
|
import com.weikou.beibeivideo.util.AlibcTradeUtil;
|
import com.weikou.beibeivideo.util.BeibeiConstant;
|
import com.weikou.beibeivideo.util.ConfigUtil;
|
import com.weikou.beibeivideo.util.JumpActivityUtil;
|
import com.weikou.beibeivideo.util.UserUtil;
|
import com.weikou.beibeivideo.widget.BadgeView;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import java.lang.reflect.Array;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
|
/**
|
* 原主页--我的-----3.2.4版本后已经放弃此页面
|
*/
|
public class MineFragment extends MyRetainViewFragment implements
|
OnClickListener, LoaderManager.LoaderCallbacks<Cursor> {
|
|
private final String TAG="MineFragment";
|
|
|
public MineFragment() {
|
super();
|
setName(MineFragment.class.getName());
|
}
|
|
private TextView tv_no_network;
|
|
|
private BadgeView mBadgeView;
|
|
private BadgeView mUpdateBadgeView;
|
|
private ConnectivityChangeHelper mChangeHelper;
|
|
private AQuery mAquery;
|
|
private TextView tv_login;// 用户名
|
private TextView tv_name;
|
private ImageView iv_user_logo;// 用户头像
|
private ImageView iv_vip;
|
private TextView tv_vip_open;
|
private LinearLayout ll_vip;
|
|
private RatioLayout rl_banner;
|
private ImageView iv_banner;
|
|
private GridView gv_content;
|
|
/**
|
* 用于表示登录状态
|
*/
|
public static boolean isLogin;
|
|
private LinearLayout ll_mine_favourite, ll_mine_follow, ll_mine_watch_history;
|
|
|
private boolean isHaveNewCom;// 是否存在新的评论消息
|
|
public static MineFragment newInstance() {
|
MineFragment fragment = new MineFragment();
|
return fragment;
|
}
|
|
@Override
|
public int getContentResource() {
|
return R.layout.mine_fragment;
|
}
|
|
@Override
|
public void onSaveInstanceState(Bundle outState) {
|
outState.putString("flash back", "show");
|
super.onSaveInstanceState(outState);
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
mAquery = new AQuery(contentView);
|
|
tv_no_network = contentView.findViewById(R.id.tv_no_network);
|
tv_no_network.setOnClickListener(this);
|
|
mChangeHelper = new ConnectivityChangeHelper(tv_no_network.getContext(),
|
new OnConnectivityChangeListener() {
|
|
@Override
|
public void onNetworkUnAvailable() {
|
tv_no_network.setVisibility(View.VISIBLE);
|
}
|
|
@Override
|
public void onWiFiAvailable() {
|
tv_no_network.setVisibility(View.GONE);
|
}
|
|
@Override
|
public void onMobileAvailable() {
|
tv_no_network.setVisibility(View.GONE);
|
}
|
});
|
|
ll_mine_favourite = contentView.findViewById(R.id.ll_mine_favourite);
|
ll_mine_follow = contentView.findViewById(R.id.ll_mine_follow);
|
ll_mine_watch_history = contentView.findViewById(R.id.ll_mine_watch_history);
|
|
|
tv_login = contentView.findViewById(R.id.mine_tv_login);
|
tv_name = contentView.findViewById(R.id.mine_tv_name);
|
iv_user_logo = contentView.findViewById(R.id.mine_ci_head);
|
iv_vip = contentView.findViewById(R.id.mine_iv_vip);
|
tv_vip_open = contentView.findViewById(R.id.tv_vip_open);
|
ll_vip = contentView.findViewById(R.id.ll_vip);
|
|
rl_banner = contentView.findViewById(R.id.rl_banner);
|
iv_banner = contentView.findViewById(R.id.iv_banner);
|
|
gv_content = contentView.findViewById(R.id.gv_content);
|
|
|
contentView.findViewById(R.id.mine_rl_head).setOnClickListener(this);
|
|
contentView.findViewById(R.id.tv_goldcorn).setOnClickListener(this);
|
|
ll_mine_favourite.setOnClickListener(this);
|
ll_mine_follow.setOnClickListener(this);
|
ll_mine_watch_history.setOnClickListener(this);
|
mAquery.id(R.id.ll_mine_novel).clicked(this);
|
|
|
tv_vip_open.setOnClickListener(this);
|
|
getLoaderManager().initLoader(0, null, this);
|
}
|
|
@Override
|
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
return new CursorLoader(iv_user_logo.getContext(), MessageTable.CONTENT_URI, null,
|
MessageTable.MESSAGE_STATUS + " = ? ", new String[]{"0"},
|
MessageTable.UPDATE_TIME + " DESC");
|
}
|
|
@Override
|
public void onLoadFinished(Loader<Cursor> arg0, Cursor data) {
|
// Swap the new cursor in. (The framework will take care of closing the
|
// old cursor once we return.)
|
|
if (mBadgeView != null) {
|
if (data != null && data.getCount() != 0 || (isLogin && isHaveNewCom)) {
|
mBadgeView.show();
|
} else {
|
mBadgeView.hide();
|
}
|
}
|
}
|
|
@Override
|
public void onLoaderReset(Loader<Cursor> arg0) {
|
// This is called when the last Cursor provided to onLoadFinished()
|
// above is about to be closed. We need to make sure we are no
|
// longer using it.
|
if (isLogin && !isHaveNewCom) {
|
mBadgeView.hide();
|
}
|
}
|
|
@Override
|
public void onClick(View view) {
|
switch (view.getId()) {
|
case R.id.iv_recommend_watch_history: {
|
startActivity(new Intent(tv_no_network.getContext(),
|
WatchHistoryActivity.class));
|
}
|
break;
|
case R.id.iv_activity_main_download: {
|
Toast.makeText(tv_no_network.getContext(), "暂时不支持下载!", Toast.LENGTH_LONG).show();
|
}
|
break;
|
case R.id.ll_activity_main_search: {
|
startActivity(new Intent(tv_no_network.getContext(),
|
SearchActivity.class));
|
}
|
break;
|
case R.id.mine_rl_head:
|
Intent intent = new Intent();
|
if (isLogin) {// 登录后 逻辑
|
intent.setClass(tv_no_network.getContext(), PersonInfoActivity.class);
|
} else {// 登录前
|
intent.setClass(tv_no_network.getContext(), LoginActivity.class);
|
|
}
|
startActivity(intent);
|
break;
|
case R.id.ll_mine_favourite:
|
startActivity(new Intent(tv_no_network.getContext(), MyFavouriteActivity.class));
|
break;
|
case R.id.ll_mine_watch_history:
|
startActivity(new Intent(tv_no_network.getContext(), WatchHistoryActivity.class));
|
break;
|
// case R.id.rl_mine_download:
|
// startActivity(new Intent(tv_no_network.getContext(), DownloadActivity.class));
|
// break;
|
case R.id.ll_mine_follow:
|
startActivity(new Intent(tv_no_network.getContext(), FollowActivity.class));
|
break;
|
|
//影视豆
|
case R.id.tv_goldcorn:
|
startActivity(new Intent(tv_no_network.getContext(), GoldCornActivity.class));
|
break;
|
|
//书架
|
case R.id.ll_mine_novel:
|
break;
|
|
case R.id.tv_vip_open:
|
if (!UserUtil.isLogin(tv_no_network.getContext())) {
|
startActivity(new Intent(tv_no_network.getContext(), LoginActivity.class));
|
return;
|
}
|
String url = ConfigUtil.getVipLink(tv_no_network.getContext());
|
if (StringUtils.isEmpty(url)) {
|
return;
|
}
|
startActivity(new Intent(tv_no_network.getContext(), BrowserActivity.class).putExtra("url", url));
|
break;
|
}
|
}
|
|
UMShareListener shareListener = new UMShareListener() {
|
@Override
|
public void onStart(SHARE_MEDIA share_media) {
|
|
}
|
|
@Override
|
public void onResult(SHARE_MEDIA share_media) {
|
Toast.makeText(tv_no_network.getContext(), "分享成功!", Toast.LENGTH_LONG).show();
|
}
|
|
@Override
|
public void onError(SHARE_MEDIA share_media, Throwable throwable) {
|
if (!UMShareAPI.get(tv_no_network.getContext()).isInstall(getActivity(), share_media)) {
|
Toast.makeText(tv_no_network.getContext(), share_media == SHARE_MEDIA.QQ ? "没有安装QQ" : "没有安装微信", Toast.LENGTH_LONG).show();
|
} else {
|
Toast.makeText(tv_no_network.getContext(), "分享出错!", Toast.LENGTH_LONG).show();
|
}
|
}
|
|
@Override
|
public void onCancel(SHARE_MEDIA share_media) {
|
Toast.makeText(tv_no_network.getContext(), "分享取消!", Toast.LENGTH_LONG).show();
|
}
|
};
|
|
private String getShareUrl() {
|
SharedPreferences preferences = tv_no_network.getContext().getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
return preferences.getString("share_url", "http://yy.umgotv.com");
|
}
|
|
private String getShareContent() {
|
SharedPreferences preferences = tv_no_network.getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String shareContent = preferences.getString(
|
"share_content",
|
"牛逼的APP,什么样的新片,大片,电视剧都有---"
|
+ getResources().getString(
|
R.string.app_name))
|
+ getShareUrl();
|
return shareContent;
|
}
|
|
/**
|
* 打开消息页面
|
*/
|
private void openMsg() {
|
EventBus.getDefault().post(new NewComment(true));
|
SharedPreferences preferences = tv_no_network.getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
Editor editor = preferences.edit();
|
editor.putBoolean("isCheckedCom", false);
|
|
editor.commit();
|
mBadgeView.hide();
|
startActivity(new Intent(tv_no_network.getContext(),
|
SystemMessageActivity.class));
|
}
|
|
/**
|
* 初始化用户登录信息
|
*/
|
private void initLoginInfo() {
|
UserInfo userInfo = UserUtil.getLoginUserInfo(getContext());
|
isLogin = userInfo != null;
|
if (userInfo != null) {
|
String portrait = userInfo.getPortrait();
|
String name = userInfo.getNickname();
|
try {
|
Glide.with(getActivity().getApplicationContext()).load(portrait).apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL)).placeholder(R.drawable.ic_portrait_default)
|
.transform(new GlideRoundTransform(getActivity(), 50))
|
.into(iv_user_logo);
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
}
|
tv_login.setVisibility(View.GONE);
|
tv_name.setVisibility(View.VISIBLE);
|
tv_name.setText(name);
|
} else {// 恢复登录前的状态
|
iv_user_logo.setImageResource(R.drawable.img_head_portrait);// 默认头像
|
tv_login.setVisibility(View.VISIBLE);
|
tv_name.setVisibility(View.GONE);
|
}
|
|
UserInfoVO userDetail = UserUtil.getLoginUserInfoDetail(getContext());
|
if (userDetail != null) {//已经登录了,且是新版本
|
//vip标识
|
if (userDetail.getVipExpireTime() != null && System.currentTimeMillis() <= userDetail.getVipExpireTime()) {
|
iv_vip.setVisibility(View.VISIBLE);
|
tv_vip_open.setText("会员续费");
|
} else {
|
iv_vip.setVisibility(View.GONE);
|
tv_vip_open.setText("开通会员");
|
}
|
} else {
|
iv_vip.setVisibility(View.GONE);
|
}
|
|
}
|
|
/**
|
* shizh用户信息的展示
|
*/
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
Log.i(TAG,"onResume");
|
// 获取缓存中的消息状态
|
SharedPreferences preferences = tv_no_network.getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
isHaveNewCom = preferences.getBoolean("isCheckedCom", false);
|
initLoginInfo();
|
mChangeHelper.registerReceiver();
|
SharedPreferences preferences2 = tv_no_network.getContext().getSharedPreferences(
|
"update", Context.MODE_PRIVATE);
|
if (mUpdateBadgeView != null) {
|
if (preferences2.getBoolean("status", false)) {
|
mUpdateBadgeView.show();
|
} else {
|
mUpdateBadgeView.hide();
|
}
|
}
|
//填充
|
BannerVO bannerVO = ConfigUtil.getMinePageBanner(getContext());
|
if (bannerVO == null) {
|
rl_banner.setVisibility(View.GONE);
|
} else {
|
rl_banner.setVisibility(View.VISIBLE);
|
rl_banner.setRatio(bannerVO.getRatio().floatValue());
|
Glide.with(this).load(bannerVO.getPicture()).transform(new GlideRoundTransform(getContext(), 5)).into(iv_banner);
|
rl_banner.setOnClickListener(new OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
JumpActivityUtil.jumpPage(getActivity(), bannerVO.getJumpDetail(), bannerVO.getParams() != null ? JSONObject.parseObject(bannerVO.getParams()) : null);
|
}
|
});
|
}
|
|
|
getPersonInfo();
|
|
if (YouthUtil.isOpenYouthMode(getContext())) {
|
gv_content.setAdapter(new MyAdapter(getYouthFunctions()));
|
mAquery.id(R.id.ll_videos).visibility(View.GONE);
|
mAquery.id(R.id.ll_vip).visibility(View.GONE);
|
} else {
|
gv_content.setAdapter(new MyAdapter(getNotYouthFunctions()));
|
mAquery.id(R.id.ll_videos).visibility(View.VISIBLE);
|
mAquery.id(R.id.ll_vip).visibility(View.VISIBLE);
|
}
|
|
|
}
|
|
@Override
|
public void onPause() {
|
Log.i(TAG,"onPause");
|
super.onPause();
|
mChangeHelper.unregisterReceiver();
|
}
|
|
@Override
|
public void onDestroy() {
|
super.onDestroy();
|
isLogin = false;
|
}
|
|
public static String getVersionName(Context context) {
|
try {
|
PackageInfo pi = context.getPackageManager().getPackageInfo(
|
context.getPackageName(), 0);
|
return pi.versionName;
|
} catch (NameNotFoundException e) {
|
e.printStackTrace();
|
return "";
|
}
|
}
|
|
private void getPersonInfo() {
|
UserUtil.updateUserInfo(getContext(), new UserUtil.IUserInfoUpdateListener() {
|
@Override
|
public void noLogin() {
|
|
}
|
|
@Override
|
public void onSuccess() {
|
initLoginInfo();
|
}
|
|
@Override
|
public void onFail(String msg) {
|
|
}
|
});
|
}
|
|
class MyAdapter extends BaseAdapter {
|
private List<Function> functionList;
|
private LayoutInflater inflater;
|
|
public MyAdapter(List<Function> functionList) {
|
this.functionList = functionList;
|
inflater = LayoutInflater.from(getContext());
|
}
|
|
@Override
|
public int getCount() {
|
return functionList == null ? 0 : functionList.size();
|
}
|
|
@Override
|
public Object getItem(int i) {
|
return functionList.get(i);
|
}
|
|
@Override
|
public long getItemId(int i) {
|
return i;
|
}
|
|
@Override
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
View root = inflater.inflate(R.layout.mine_function, null);
|
TextView tv_name = root.findViewById(R.id.tv_name);
|
ImageView iv_icon = root.findViewById(R.id.iv_icon);
|
RelativeLayout rl_container = root.findViewById(R.id.rl_content);
|
final Function function = functionList.get(i);
|
if (function.getType() == Function.Type.msg) {
|
mBadgeView = new BadgeView(iv_user_logo.getContext(), rl_container);
|
mBadgeView.setBackgroundResource(R.drawable.ic_red_dot);
|
mBadgeView.setTextSize(1);
|
mBadgeView.setText("");
|
mBadgeView.setBadgeMargin(DimenUtils.dipToPixels(20, tv_no_network.getContext()));
|
|
|
mUpdateBadgeView = new BadgeView(getContext(), rl_container);
|
mUpdateBadgeView.setBackgroundResource(R.drawable.ic_red_dot);
|
mUpdateBadgeView.setTextSize(1);
|
mUpdateBadgeView.setText("");
|
mUpdateBadgeView.setBadgeMargin(DimenUtils.dipToPixels(20,
|
tv_no_network.getContext()));
|
}
|
|
tv_name.setText(function.getName());
|
iv_icon.setImageResource(function.getResourceId());
|
root.setOnClickListener(new OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
|
if (function.getType() == Function.Type.msg) {
|
openMsg();
|
} else if (function.getType() == Function.Type.share) {
|
new ShareAPPDialog.Builder(getActivity()).create().show();
|
} else if (function.getType() == Function.Type.help) {
|
startActivity(new Intent(tv_no_network.getContext(),
|
HelpAndTicklingActivity.class));
|
} else if (function.getType() == Function.Type.buy) {
|
String url = ConfigUtil.getBuyRecordUrl(getContext());
|
if (StringUtils.isEmpty(url))
|
return;
|
Intent intent11 = new Intent(getContext(), BrowserActivity.class);
|
intent11.putExtra("url", url);
|
startActivity(intent11);
|
} else if (function.getType() == Function.Type.youth) {
|
Intent intent11 = new Intent(getContext(), YouthActivity.class);
|
startActivity(intent11);
|
} else if (function.getType() == Function.Type.about) {
|
Intent intent1 = new Intent(getContext(), BrowserActivity.class);
|
intent1.putExtra("url", BeibeiConstant.ABOUT_US);
|
startActivity(intent1);
|
} else if (function.getType() == Function.Type.setting) {
|
startActivity(new Intent(tv_no_network.getContext(), SettingsActivity.class));
|
}
|
}
|
});
|
|
return root;
|
}
|
|
}
|
|
private List<Function> getNotYouthFunctions() {
|
List<Function> list = new ArrayList<>();
|
list.add(new Function(R.drawable.ic_mine_message_w, "站内消息", Function.Type.msg));
|
list.add(new Function(R.drawable.ic_mine_share_w, "分享软件", Function.Type.share));
|
list.add(new Function(R.drawable.ic_mine_help_w, "帮助中心", Function.Type.help));
|
list.add(new Function(R.drawable.icon_mine_buy_record, "购买记录", Function.Type.buy));
|
list.add(new Function(R.drawable.icon_mine_youth, "青少年模式", Function.Type.youth));
|
list.add(new Function(R.drawable.ic_mine_about_us_w, "关于我们", Function.Type.about));
|
list.add(new Function(R.drawable.ic_mine_settings_w, "设置", Function.Type.setting));
|
return list;
|
}
|
|
private List<Function> getYouthFunctions() {
|
List<Function> list = new ArrayList<>();
|
list.add(new Function(R.drawable.ic_mine_share_w, "分享软件", Function.Type.share));
|
list.add(new Function(R.drawable.ic_mine_help_w, "帮助中心", Function.Type.help));
|
list.add(new Function(R.drawable.icon_mine_youth, "青少年模式", Function.Type.youth));
|
list.add(new Function(R.drawable.ic_mine_about_us_w, "关于我们", Function.Type.about));
|
list.add(new Function(R.drawable.ic_mine_settings_w, "设置", Function.Type.setting));
|
return list;
|
}
|
|
|
static class Function {
|
|
enum Type {
|
msg, share, help, buy, youth, about, setting
|
}
|
|
private int resourceId;
|
private String name;
|
private Type type;
|
|
public Function(int resourceId, String name, Type type) {
|
this.resourceId = resourceId;
|
this.name = name;
|
this.type = type;
|
}
|
|
public int getResourceId() {
|
return resourceId;
|
}
|
|
public void setResourceId(int resourceId) {
|
this.resourceId = resourceId;
|
}
|
|
public String getName() {
|
return name;
|
}
|
|
public void setName(String name) {
|
this.name = name;
|
}
|
|
public Type getType() {
|
return type;
|
}
|
|
public void setType(Type type) {
|
this.type = type;
|
}
|
}
|
|
}
|