package com.tejia.lijin.app.ui.main;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.content.pm.ActivityInfo;
|
import android.content.res.Configuration;
|
import android.content.res.Resources;
|
import android.graphics.Color;
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.view.KeyEvent;
|
import android.view.MotionEvent;
|
import android.view.View;
|
import android.view.ViewTreeObserver;
|
import android.view.Window;
|
import android.view.WindowManager;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.RadioButton;
|
import android.widget.RadioGroup;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.app.hubert.guide.util.ScreenUtils;
|
import com.heytap.msp.push.HeytapPushManager;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.BuXinConstant;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.ShoppingApplication;
|
import com.tejia.lijin.app.badge.BadgeUtils;
|
import com.tejia.lijin.app.callBack.DragFloatActionInterface;
|
import com.tejia.lijin.app.callBack.LonginTaobaoCallback;
|
import com.tejia.lijin.app.callBack.MessagePush;
|
import com.tejia.lijin.app.entity.EventMessageEntity;
|
import com.tejia.lijin.app.entity.TrendsCategory;
|
import com.tejia.lijin.app.entity.eventbus.HomeTabChangeEvent;
|
import com.tejia.lijin.app.entity.eventbus.UserProtocolEvent;
|
import com.tejia.lijin.app.receiver.MiPushMessageReceiver;
|
import com.tejia.lijin.app.ui.HMPushReceiveActivity;
|
import com.tejia.lijin.app.ui.PushOpenClickActivity;
|
import com.tejia.lijin.app.ui.dialog.LoginFirstDialog;
|
import com.tejia.lijin.app.ui.mine.ShoppingTrolleyActivity;
|
import com.tejia.lijin.app.util.DragFloatActionButton;
|
import com.tejia.lijin.app.util.LoginTaobao;
|
import com.tejia.lijin.app.util.RecordImageTextVideo;
|
import com.tejia.lijin.app.util.SystemParamsUtil;
|
import com.tejia.lijin.app.util.ToolUtil;
|
import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
|
import com.tejia.lijin.app.util.clipboard.IClipboardContentListener;
|
import com.tejia.lijin.app.util.ui.ClipboardContentRecommendUtil;
|
import com.tejia.lijin.app.util.ui.HomeUIUtil;
|
import com.tejia.lijin.app.util.umengCustomEvent.MainCustomEvent;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
import com.umeng.analytics.MobclickAgent;
|
import com.vivo.push.PushClient;
|
import com.wpc.library.okhttp.OkHttpUtils;
|
import com.wpc.library.util.FragmentSwitchHelper;
|
import com.wpc.library.util.NetUtils;
|
import com.wpc.library.util.common.StringUtils;
|
import com.xiaomi.mipush.sdk.MiPushMessage;
|
import com.yeshi.push.PushAppInfoFactory;
|
import com.yeshi.push.PushUtil;
|
import com.yeshi.push.entity.PushApps;
|
import com.yeshi.push.entity.PushRomType;
|
|
import org.apache.http.Header;
|
import org.json.JSONArray;
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
import java.lang.reflect.Field;
|
import java.text.ParseException;
|
import java.util.List;
|
|
import androidx.annotation.NonNull;
|
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.FragmentActivity;
|
import de.greenrobot.event.EventBus;
|
|
|
/**
|
* 主页
|
*/
|
public class MainActivity extends FragmentActivity
|
implements DragFloatActionInterface {
|
|
private RadioGroup rg_nav;
|
private View v_no_login;
|
private FragmentSwitchHelper mFragmentSwitchHelper;
|
|
|
private SharedPreferences spkefu;
|
private ImageView img;
|
private TextView tv_msg_count;
|
private DragFloatActionButton acbutton;
|
|
String tag1 = "systemclient/getsystemclientparams";
|
String tag2 = "search/getRecommendInfo";
|
String tag3 = "msg/getUnReadMsgCount";
|
String tag4 = "msg/uploadLatestKeFuMsg";
|
String tag5 = "msg/getHomeMsgListNew";
|
String tag6 = "push/bindHWPush";
|
|
//其他页面传入的参数
|
private Integer fromTab = null;
|
private Integer fromSubTab = null;
|
|
private void getIntentParams() {
|
fromTab = getIntent().getIntExtra("tab", -1);
|
fromSubTab = getIntent().getIntExtra("subTab", -1);
|
if (fromTab == -1)
|
fromTab = null;
|
if (fromSubTab == -1)
|
fromSubTab = null;
|
}
|
|
@Override
|
public void onConfigurationChanged(Configuration newConfig) {
|
if (newConfig.fontScale != 1)//非默认值
|
getResources();
|
super.onConfigurationChanged(newConfig);
|
}
|
|
@Override
|
public Resources getResources() {
|
Resources res = super.getResources();
|
// if (res.getConfiguration().fontScale != 1) {//非默认值
|
Configuration newConfig = new Configuration();
|
newConfig.setToDefaults();//设置默认
|
res.updateConfiguration(newConfig, res.getDisplayMetrics());
|
// }
|
return res;
|
}
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
ToolUtil.setCustomDensity(this, ShoppingApplication.application);
|
super.onCreate(savedInstanceState);
|
getIntentParams();
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
try {
|
Class decorViewClazz = Class.forName("com.android.internal.policy.DecorView");
|
Field field = decorViewClazz.getDeclaredField("mSemiTransparentStatusBarColor");
|
field.setAccessible(true);
|
field.setInt(getWindow().getDecorView(), Color.TRANSPARENT); //改为透明
|
} catch (Exception e) {
|
}
|
}
|
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 锁定竖屏
|
setContentView(R.layout.activity_main);
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
Window window = getWindow();
|
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
|
// window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
window.setStatusBarColor(Color.TRANSPARENT);
|
int result = 0;
|
int resourceId = getResources().getIdentifier("status_bar_height",
|
"dimen", "android");
|
if (resourceId > 0) {
|
result = getResources().getDimensionPixelSize(resourceId);
|
}
|
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
|
result);
|
findViewById(R.id.v_status_bar).setLayoutParams(params);
|
findViewById(R.id.v_status_bar).setBackground(HomeUIUtil.getHomeTopBg(getApplicationContext()));
|
} else {
|
findViewById(R.id.v_status_bar).setVisibility(View.GONE);
|
}
|
|
|
EventBus.getDefault().register(this);
|
sp = getSharedPreferences("user", MODE_PRIVATE);
|
mFragmentSwitchHelper = FragmentSwitchHelper.create(
|
R.id.fl_main_fragment_container, getSupportFragmentManager(),
|
new RecommendTopFragment(), HotSalesFragment.newInstance(5, "全部", new TrendsCategory(0, "")), new MessageFragment(),
|
BetterGoodsFragment.newInstance(7 + "", "0"), new MineFragment());
|
|
rg_nav = findViewById(R.id.rg_nav);
|
rg_nav.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
switch (checkedId) {
|
case R.id.rb_nav_recommend: {//首页
|
MainCustomEvent.mainHome(MainActivity.this);
|
mFragmentSwitchHelper
|
.changeFragment(RecommendTopFragment.class);
|
}
|
break;
|
case R.id.rb_nav_hot_sale: {//热卖
|
MainCustomEvent.mainActivity(MainActivity.this);
|
mFragmentSwitchHelper
|
.changeFragment(HotSalesFragment.class);
|
}
|
break;
|
case R.id.rb_nav_better_goods://好物
|
mFragmentSwitchHelper.changeFragment(BetterGoodsFragment.class);
|
break;
|
|
case R.id.rb_nav_mine: {//我的
|
MainCustomEvent.mainMine(MainActivity.this);
|
mFragmentSwitchHelper.changeFragment(MineFragment.class);
|
}
|
break;
|
default:
|
break;
|
}
|
}
|
});
|
|
getSystemParams();
|
v_no_login = findViewById(R.id.v_no_login);
|
acbutton = findViewById(R.id.actionButton);
|
tv_msg_count = findViewById(R.id.tv_msg_count);//消息数量
|
acbutton.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
//登陆
|
if (UserUtil.isLogin(getApplicationContext())) {
|
LoginTaobao.getLoginTaobao(MainActivity.this, new LonginTaobaoCallback() {
|
@Override
|
public void onSuccess() {
|
startActivity(new Intent(MainActivity.this, ShoppingTrolleyActivity.class));
|
}
|
|
@Override
|
public void onError() {
|
Toast.makeText(MainActivity.this, "登陆淘宝失败", Toast.LENGTH_SHORT).show();
|
}
|
});
|
} else {
|
UserUtil.jumpLogin(MainActivity.this);
|
}
|
}
|
});
|
img = findViewById(R.id.actionButton_img);
|
|
spkefu = getSharedPreferences("kefurecord", Context.MODE_PRIVATE);//是否打开过客服 记录
|
|
//获取 取消悬浮控件的宽高
|
ViewTreeObserver vto2 = img.getViewTreeObserver();
|
vto2.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
@Override
|
public void onGlobalLayout() {
|
img.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
//传入 主界面 指定控件的宽高
|
if (acbutton != null) {
|
acbutton.setWidthHeight((int) (img.getWidth() * 0.77), (int) (img.getHeight() * 0.77));
|
}
|
img.setVisibility(View.GONE);//隐藏
|
}
|
});
|
if (fromTab != null && fromTab > 0 && fromTab < 5) {
|
choiceTab(fromTab, fromSubTab);
|
} else
|
((RadioButton) findViewById(R.id.rb_nav_recommend)).setChecked(true);
|
|
//注册推送
|
initPush();
|
|
|
}
|
|
private void initPush() {
|
PushApps pushApps = new PushApps();
|
pushApps.setHw(PushAppInfoFactory.createHuaWei(getResources().getString(R.string.push_hw_appid)));
|
pushApps.setOppo(PushAppInfoFactory.createOPPO(getResources().getString(R.string.push_oppo_app_key), getResources().getString(R.string.push_oppo_app_secret)));
|
pushApps.setVivo(PushAppInfoFactory.createVIVO(getResources().getString(R.string.push_vivo_app_id), getResources().getString(R.string.push_vivo_api_key)));
|
pushApps.setXm(PushAppInfoFactory.createXM(getResources().getString(R.string.mipush_appid), getResources().getString(R.string.mipush_appkey)));
|
PushUtil.inintPush(ShoppingApplication.application, pushApps, new PushUtil.ITokenListener() {
|
|
@Override
|
public void onToken(final PushRomType romType,final String regId) {
|
runOnUiThread(new Runnable() {
|
@Override
|
public void run() {
|
ShoppingApi.bindPushToken(getApplicationContext(), UserUtil.getUid(getApplicationContext()), romType, regId, null);
|
}
|
});
|
|
}
|
});
|
}
|
|
private void choiceTab(Integer tab, Integer subTab) {
|
if (tab == null)
|
return;
|
if (tab != null && tab < 5) {
|
switch (tab) {
|
case 0:
|
((RadioButton) findViewById(R.id.rb_nav_recommend)).setChecked(true);
|
break;
|
case 1:
|
if (subTab != null && subTab > -1) {
|
//动态需要传入tab
|
TrendsTopFragment trendsTopFragment = (TrendsTopFragment) mFragmentSwitchHelper.getFragmentByName(TrendsTopFragment.class.getName());
|
trendsTopFragment.setTabIndex(subTab);
|
}
|
((RadioButton) findViewById(R.id.rb_nav_hot_sale)).setChecked(true);
|
break;
|
case 2:
|
((RadioButton) findViewById(R.id.rb_nav_better_goods)).setChecked(true);
|
break;
|
case 3:
|
((RadioButton) findViewById(R.id.rb_nav_mine)).setChecked(true);
|
break;
|
}
|
}
|
}
|
|
SharedPreferences sp;
|
|
/**
|
* 系统补充参数请求
|
*/
|
private void getSystemParams() {
|
ShoppingApi.getSystemParams(MainActivity.this, UserUtil.getUid(ShoppingApplication.application), new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optString("code").equalsIgnoreCase("0")) {
|
JSONArray array = jsonObject.optJSONObject("data").optJSONArray("systemClientParamsList");
|
SystemParamsUtil.saveParams(getApplicationContext(), array);
|
boolean input = sp.getBoolean("isFirstInput", true);
|
boolean isLogin = UserUtil.isLogin(getApplicationContext());
|
//新人好礼1元红包
|
if (input && !isLogin && sp.getString("newuser", "1").equalsIgnoreCase("0")) {
|
isFirstInput();
|
}
|
//记录优惠券 图文视频链接 购物车显示
|
RecordImageTextVideo textVideo = new RecordImageTextVideo(MainActivity.this);
|
textVideo.isRecord(jsonObject);
|
//服务器让显示 购物车&&本地也让显示
|
if (textVideo.getCart_float().equals("1") && textVideo.getLocalCart_float() != 1
|
&& UserUtil.isLogin(getApplicationContext())) {
|
acbutton.setVisibility(View.VISIBLE);
|
} else {//隐藏购物车
|
acbutton.setVisibility(View.GONE);
|
}
|
first = 1;//请求成功
|
// startService(new Intent(MainActivity.this, ClipbroadContentChangeService.class));
|
}
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString, throwable);
|
first = 2;//请求失败
|
}
|
});
|
}
|
|
private void getGoodsInfo(String description) {
|
if (StringUtils.isEmpty(description))
|
return;
|
|
ClipboardContentRecommendUtil.getRecommendInfo(description, this);
|
}
|
|
private Dialog dialog = null;
|
private int first = 0;
|
|
@Override
|
protected void onResume() {
|
super.onResume();
|
if (BuXinConstant.GO_SCAN) {
|
BuXinConstant.GO_SCAN = false;
|
((RadioButton) findViewById(R.id.rb_nav_recommend)).setChecked(true);
|
}
|
boolean isLogin = UserUtil.isLogin(getApplicationContext());
|
v_no_login.setVisibility(isLogin ? View.INVISIBLE : View.VISIBLE);
|
getUnReadMsgCount(UserUtil.getUid(ShoppingApplication.application));//消息 未读数量
|
|
if (MiPushMessageReceiver.miPushMessage != null) {//打开小米推送
|
MiPushMessage message = MiPushMessageReceiver.miPushMessage;
|
MiPushMessageReceiver.miPushMessage = null;
|
MiPushMessageReceiver.startActivity(this, this, message);
|
} else if (!StringUtils.isEmpty(HMPushReceiveActivity.HMPushInfo)) {//打开华为推送
|
String str = HMPushReceiveActivity.HMPushInfo;
|
HMPushReceiveActivity.HMPushInfo = null;
|
HMPushReceiveActivity.startActivity(this, str);
|
} else if (!StringUtils.isEmpty(ToolUtil.OPPOPushInfo)) {//打开OPPO推送
|
String str = ToolUtil.OPPOPushInfo;
|
ToolUtil.OPPOPushInfo = null;
|
ToolUtil.startActivity(this, this, str);
|
} else if (!StringUtils.isEmpty(ToolUtil.VIVOPushInfo)) {//打开VIVO推送
|
String str = ToolUtil.VIVOPushInfo;
|
ToolUtil.VIVOPushInfo = null;
|
ToolUtil.startActivity(this, this, str);
|
}
|
getRecommendInfoFromClipboard();
|
//是第二次进入
|
if (first == 1 || first == 2) {
|
//记录优惠券 图文视频链接 购物车显示
|
RecordImageTextVideo textVideo = new RecordImageTextVideo(MainActivity.this);
|
//服务器让显示 购物车&&本地也让显示不为1
|
if (textVideo.getCart_float().equals("1") && textVideo.getLocalCart_float() != 1 &&
|
UserUtil.isLogin(getApplicationContext())) {
|
acbutton.setVisibility(View.VISIBLE);
|
//点击过 再显示(让按钮复位)
|
if (textVideo.getLocalCart_float() == 2) {
|
int hegih = ScreenUtils.getScreenHeight(this);
|
int width = ScreenUtils.getScreenWidth(this);
|
acbutton.setX(width - acbutton.getWidth());
|
acbutton.setY((hegih - ScreenUtils.dp2px(this, 560)));
|
textVideo.setLocalCart_float(0);//复位 清除 点击状态(点击过显示或隐藏)
|
}
|
} else {//隐藏购物车
|
acbutton.setVisibility(View.GONE);
|
}
|
}
|
PushOpenClickActivity.resumeJumpActivity(this);
|
}
|
|
private void getRecommendInfoFromClipboard() {
|
if (!UserUtil.isAgreeUserProtocol(getApplicationContext()) || !UserUtil.isShownUserGuide(getApplicationContext()))
|
return;
|
|
ClipboardUtil.getClipboardContent(this, new IClipboardContentListener() {
|
@Override
|
public void getContent(String content) {
|
if ((!StringUtils.isEmpty(content)) && getSharedPreferences("user", MODE_PRIVATE).getString("copy", "0").equalsIgnoreCase("1")) {
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putBoolean("isClipBroadChanged", true);
|
editor.commit();
|
}
|
|
if (sp.getBoolean("isClipBroadChanged", false)) {
|
if (dialog != null && dialog.isShowing()) {
|
dialog.dismiss();
|
dialog = null;
|
}
|
if (!StringUtils.isEmpty(content)) {
|
getGoodsInfo(content);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putBoolean("isClipBroadChanged", false);
|
editor.commit();
|
}
|
}
|
}
|
});
|
}
|
|
|
private int totalCount = 0;//总的消息未读数
|
|
/**
|
* 消息 未读数量
|
*
|
* @param uid
|
*/
|
private void getUnReadMsgCount(Long uid) {
|
ShoppingApi.getUnReadMsgCount(this, uid, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
if (jsonObject.optJSONObject("data").optInt("totalCount") > 0) {
|
totalCount = jsonObject.optJSONObject("data").optInt("totalCount");
|
} else {
|
totalCount = 0;
|
}
|
} else {
|
totalCount = 0;
|
}
|
|
tv_msg_count.setVisibility(totalCount > 0 ? View.VISIBLE : View.INVISIBLE);
|
if (totalCount > 0) {
|
tv_msg_count.setText(totalCount >= 100 ? "99+" : (totalCount + ""));
|
}
|
|
setUnReadMsgCount(jsonObject);
|
getgetHomeMsgList();//获取未读消息条数
|
}
|
});
|
}
|
|
/**
|
* 设置 未读消息数量
|
*/
|
public void setUnReadMsgCount(JSONObject jsonObject) {
|
this.totalCount = 0;//jsonObject.optJSONObject("data").optInt("totalCount");
|
showreddot();
|
|
// Log.e("eee", "Main 消息 未读数量: " + totalCount);
|
if (totalCount > 0) {
|
if (!Build.BRAND.toLowerCase().equalsIgnoreCase("xiaomi")) {
|
//设置角标
|
BadgeUtils.setCount(totalCount, MainActivity.this);
|
}
|
} else {
|
if (Build.BRAND.toLowerCase().equalsIgnoreCase("huawei")
|
|| Build.BRAND.toLowerCase().equalsIgnoreCase("honor")) {
|
//设置角标 为0
|
BadgeUtils.setCount(totalCount, MainActivity.this);
|
}
|
}
|
//展示我的 红点
|
// int msgCount = jsonObject.optJSONObject("data").optInt("mineCount");
|
}
|
|
private void isFirstInput() {
|
LoginFirstDialog.Builder builder = new LoginFirstDialog.Builder(this);
|
builder.setPositiveButton("", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
UserUtil.jumpLogin(MainActivity.this);
|
dialog.dismiss();
|
}
|
});
|
builder.setNegativeButton("", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
dialog.dismiss();
|
}
|
});
|
builder.create().show();
|
}
|
|
@Override
|
protected void onPause() {
|
super.onPause();
|
MobclickAgent.onPageEnd("主页");
|
MobclickAgent.onPause(this);
|
//注销美洽客服广播
|
}
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
EventBus.getDefault().unregister(this);
|
OkHttpUtils.getInstance().cancelTag(tag1);
|
OkHttpUtils.getInstance().cancelTag(tag2);
|
OkHttpUtils.getInstance().cancelTag(tag3);
|
OkHttpUtils.getInstance().cancelTag(tag4);
|
OkHttpUtils.getInstance().cancelTag(tag5);
|
OkHttpUtils.getInstance().cancelTag(tag6);
|
}
|
|
private long mExitTime;
|
|
@Override
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if ((System.currentTimeMillis() - mExitTime) > 2000) {
|
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
|
mExitTime = System.currentTimeMillis();
|
return true;
|
}
|
}
|
return super.onKeyDown(keyCode, event);
|
}
|
|
/**
|
* 接收到推送消息 发给消息接口
|
*/
|
private MessagePush messagePush;
|
|
public void setMessagePush(MessagePush m) {
|
messagePush = m;
|
}
|
|
/**
|
* 客服推送消息 通过EventBut 接受 从新请求一次消息未读数量
|
* 此方法在传递给消息页面,让消息页面重新请求一次刷新方法
|
*
|
* @param entity
|
*/
|
public void onEventMainThread(EventMessageEntity entity) {
|
getUnReadMsgCount(UserUtil.getUid(ShoppingApplication.application));
|
if (messagePush != null) {
|
// 这里就会调用我们Fragment中的MessagePush方法
|
messagePush.MessagePush(true);//传入消息推送
|
}
|
}
|
|
|
public void onEventMainThread(HomeTabChangeEvent entity) {
|
choiceTab(entity.getTab(), entity.getSubTab());
|
}
|
|
|
//用户协议同意监听
|
public void onEventMainThread(UserProtocolEvent event) {
|
getRecommendInfoFromClipboard();
|
}
|
|
|
/**
|
* 获取主页消息接口
|
*/
|
public interface getHomeMsgListListener {
|
void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws JSONException, ParseException;
|
|
void onFinish();
|
|
void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable);
|
}
|
|
|
/**
|
* 美洽未读总条数
|
*/
|
private int mqtotaCount = 0;
|
|
/**
|
* 获取美洽未读总条数
|
*
|
* @param jsonObject
|
*/
|
private void getUnreadMessages(JSONObject jsonObject) throws JSONException {
|
mqtotaCount = 0;
|
showreddot();
|
}
|
|
/**
|
* 显示红点
|
*/
|
private void showreddot() {
|
//TODO 显示红点
|
}
|
|
/**
|
* 清除美洽 消息
|
*/
|
public void setclear(boolean all) {
|
mqtotaCount = 0;
|
if (all) {
|
totalCount = 0;
|
}
|
showreddot();
|
//设置角标
|
if (Build.BRAND.toLowerCase().equalsIgnoreCase("huawei")
|
|| Build.BRAND.toLowerCase().equalsIgnoreCase("honor")) {
|
//设置角标 为0
|
BadgeUtils.setCount(totalCount, MainActivity.this);
|
} else if (Build.BRAND.toLowerCase().equalsIgnoreCase("xiaomi")) {
|
// NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
// //移除标记为id的通知 (只是针对当前Context下的所有Notification)
|
//// notificationManager.cancel(notificationId);
|
// //移除所有通知
|
// if (notificationManager != null)
|
// notificationManager.cancelAll();
|
} else {
|
|
}
|
|
}
|
|
int mPage = 1;
|
|
/**
|
* 设置主页消息 分页
|
*
|
* @param page
|
*/
|
public void setmPage(int page) {
|
this.mPage = page;
|
}
|
|
private void getgetHomeMsgList() {
|
getMessageMain(new getHomeMsgListListener() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws JSONException, ParseException {
|
getUnreadMessages(jsonObject);//获取未读消息条数
|
}
|
|
@Override
|
public void onFinish() {
|
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
|
}
|
}, false);//不在继续请求 消息列表
|
}
|
|
/**
|
* 获取主页消息列表
|
*
|
* @param homeMsgListListener
|
* @param request 是否继续请求
|
*/
|
public void getMessageMain(final getHomeMsgListListener homeMsgListListener, final boolean request) {
|
//上传 客服消息
|
setuploadLatestKeFuMsg();
|
if (request)
|
getHomeMsgList(homeMsgListListener);//获取主页消息列表
|
}
|
|
/**
|
* 上传最近的客服消息
|
*/
|
private void setuploadLatestKeFuMsg() {
|
//请求服务器
|
if (spkefu.getString("request", "").equals("true")) {
|
String time = spkefu.getString("contenttime", "");
|
String content = spkefu.getString("content", "");
|
ShoppingApi.uploadLatestKeFuMsg(this, content, time, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
SharedPreferences.Editor editor = spkefu.edit();
|
editor.putString("request", "false");//是否请求服务器
|
editor.apply();
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString, throwable);
|
SharedPreferences.Editor editor = spkefu.edit();
|
editor.putString("request", "false");//是否请求服务器
|
editor.apply();
|
}
|
});
|
}
|
|
}
|
|
/**
|
* 主页消息列表
|
*
|
* @param homeMsgListListener
|
*/
|
private void getHomeMsgList(final getHomeMsgListListener homeMsgListListener) {
|
|
ShoppingApi.getHomeMsgList(this, UserUtil.getUid(ShoppingApplication.application), mPage + "", new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
homeMsgListListener.onSuccessPerfect(statusCode, headers, jsonObject);
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
// Log.e("mResult", "getHomeMsgList---onFinish()");
|
homeMsgListListener.onFinish();
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString, throwable);
|
homeMsgListListener.onFailure(statusCode, headers, responseString, throwable);
|
}
|
});
|
}
|
|
/**
|
* 保存MyTouchListener接口的列表
|
*/
|
private MyTouchListener myTouchListeners;
|
|
/**
|
* 提供给Fragment通过getActivity()方法来注册自己的触摸事件的方法
|
*/
|
public void registerMyTouchListener(MyTouchListener listener) {
|
myTouchListeners = listener;
|
}
|
|
/**
|
* 提供给Fragment通过getActivity()方法来取消注册自己的触摸事件的方法
|
*/
|
public void unRegisterMyTouchListener() {
|
myTouchListeners = null;
|
}
|
|
/**
|
* activity 的触摸事件
|
*
|
* @param ev
|
* @return
|
*/
|
@Override
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
if (myTouchListeners != null) {
|
myTouchListeners.onTouchEvent(ev);
|
}
|
return super.dispatchTouchEvent(ev);
|
}
|
|
/**
|
* Fragment中不没有onTouchEvent方法 在mainactivity 中检测在传入Fragment中
|
*/
|
public interface MyTouchListener {
|
/**
|
* onTOuchEvent的实现
|
*/
|
void onTouchEvent(MotionEvent event);
|
}
|
|
/**
|
* Fragment中不会回调onRequestPermissionsResult方法,它会回调到Activity中的onRequestPermissionsResult方法
|
* 在Activity中的onRequestPermissionsResult方法中进行处理让它把改事件传递到我们的fragment中。
|
*
|
* @param requestCode
|
* @param permissions
|
* @param grantResults
|
*/
|
@Override
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
// 获取到Activity下的Fragment
|
List<Fragment> fragments = getSupportFragmentManager().getFragments();
|
if (fragments != null) {
|
// 查找在Fragment中onRequestPermissionsResult方法并调用
|
for (Fragment fragment : fragments) {
|
if (fragment != null && fragment.getClass().getName().equals("com.tejia.lijin.app.ui.main.MineFragment")) {
|
// 这里就会调用我们Fragment中的onRequestPermissionsResult方法
|
fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
break;
|
}
|
}
|
}
|
if (fragments != null) {
|
fragments.clear();
|
}
|
}
|
|
private static long lastBindHWTime = 0;
|
|
/**
|
* 开启或关闭推送
|
*/
|
public void onPush_OFF_NO() {
|
// Log.e("eee", "开启或关闭推送: ");
|
// ToolUtil.setPush_OFF_NO(this);
|
}
|
|
/**
|
* 返回 是否进入 删除区域
|
*
|
* @param Width 宽度距离判断(购物车到达指定宽度 true,否则false)
|
* @param Heigh 高度距离判断(购物车到达指定高度 true,否则false)
|
*/
|
@Override
|
public void isReturn(boolean Width, boolean Heigh) {
|
if (Width && Heigh) {
|
acbutton.setVisibility(View.GONE);
|
// img.setVisibility(View.GONE);
|
if (acbutton.getVisibility() == View.GONE) {
|
acbutton.postDelayed(new Runnable() {
|
@Override
|
public void run() {
|
img.setVisibility(View.GONE);
|
// 购物车隐藏
|
RecordImageTextVideo textVideo = new RecordImageTextVideo(MainActivity.this);
|
textVideo.setLocalCart_float(1);//不在显示购物车
|
}
|
}, 200);
|
}
|
}
|
}
|
|
/**
|
* 显示状态
|
*
|
* @param isDrag 移动状态(购物车移动true,停止false)
|
* @param display 是否显示(购物车显示true,隐藏 false)
|
*/
|
@Override
|
public void isDrag(boolean isDrag, boolean display) {
|
//移动中
|
if (isDrag) {
|
img.setVisibility(View.VISIBLE);
|
} else {//停止移动
|
if (display) {//显示
|
img.setVisibility(View.VISIBLE);
|
} else {//隐藏
|
img.setVisibility(View.GONE);
|
}
|
}
|
}
|
|
@Override
|
protected void onNewIntent(Intent intent) {
|
super.onNewIntent(intent);
|
int p = intent.getIntExtra("p", 0);
|
switch (p) {
|
case 0:
|
rg_nav.check(R.id.rb_nav_recommend);
|
|
break;
|
case 1:
|
rg_nav.check(R.id.rb_nav_hot_sale);
|
break;
|
case 2:
|
rg_nav.check(R.id.rb_nav_better_goods);
|
break;
|
case 3:
|
rg_nav.check(R.id.rb_nav_mine);
|
break;
|
}
|
|
}
|
}
|