admin
2021-05-15 2aead6275fdd1bbbd778abc0e85663a2578fab06
app/src/main/java/com/tejia/lijin/app/ui/main/MainActivity.java
@@ -21,7 +21,10 @@
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.Toast;
@@ -30,6 +33,10 @@
import com.coloros.mcssdk.PushManager;
import com.huawei.android.hms.agent.HMSAgent;
import com.huawei.android.hms.agent.push.handler.GetTokenHandler;
import com.tejia.lijin.app.entity.TrendsCategory;
import com.tejia.lijin.app.ui.recommend.GoodsDetailActivity;
import com.tejia.lijin.app.ui.trends.SendCircleFragmet;
import com.tejia.lijin.app.util.TopStatusSettings;
import com.tejia.lijin.app.util.ui.HomeUIUtil;
import com.umeng.analytics.MobclickAgent;
import com.vivo.push.PushClient;
@@ -144,7 +151,6 @@
        super.onCreate(savedInstanceState);
        getIntentParams();
        findViewById(R.id.v_status_bar).setBackground(HomeUIUtil.getHomeTopBg("#FF227B", "#FF2A3E"));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            try {
@@ -155,14 +161,40 @@
            } 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.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);
            }
            //设置状态栏文字颜色及图标为深色
//            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            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("#FF227B", "#FF2A3E"));
        } 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(), new BrandFragment(), new MessageFragment(),
                new TrendsTopFragment(), new MineFragment());
                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() {
@@ -178,11 +210,11 @@
                    case R.id.rb_nav_hot_sale: {//热卖
                        MainCustomEvent.mainActivity(MainActivity.this);
                        mFragmentSwitchHelper
                                .changeFragment(TrendsTopFragment.class);
                                .changeFragment(HotSalesFragment.class);
                    }
                    break;
                    case R.id.rb_nav_record://足迹
                        mFragmentSwitchHelper.changeFragment(BrandFragment.class);
                    case R.id.rb_nav_better_goods://好物
                        mFragmentSwitchHelper.changeFragment(BetterGoodsFragment.class);
                        break;
                    case R.id.rb_nav_mine: {//我的
@@ -251,6 +283,20 @@
        registeredOPPOId();//上传OPPO_RegId
//        onPush_OFF_NO();//检测是否打开推送
        registeredVIVOId();//上传VIVO_RegId
        tv_msg_num2.postDelayed(new Runnable() {
            @Override
            public void run() {
                //测试
                Bundle bundle = new Bundle();
                bundle.putString("goodsId", "19711731038");
                bundle.putString("goodsType", 1+"");
                startActivity(new Intent(getApplicationContext(), GoodsDetailActivity.class).putExtras(bundle));
            }
        },5000);
    }
    private void choiceTab(Integer tab, Integer subTab) {
@@ -270,7 +316,7 @@
                    ((RadioButton) findViewById(R.id.rb_nav_hot_sale)).setChecked(true);
                    break;
                case 2:
                    ((RadioButton) findViewById(R.id.rb_nav_record)).setChecked(true);
                    ((RadioButton) findViewById(R.id.rb_nav_better_goods)).setChecked(true);
                    break;
                case 3:
                    ((RadioButton) findViewById(R.id.rb_nav_mine)).setChecked(true);
@@ -322,9 +368,7 @@
     * 系统补充参数请求
     */
    private void getSystemParams() {
        String uid = getSharedPreferences("user",
                Context.MODE_PRIVATE).getString("uid", "");
        ShoppingApi.getSystemParams(MainActivity.this, uid, new BasicTextHttpResponseHandler() {
        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")) {
@@ -378,7 +422,7 @@
        }
        boolean isLogin = sp.getBoolean("isLogin", false);
        v_no_login.setVisibility(isLogin ? View.INVISIBLE : View.VISIBLE);
        getUnReadMsgCount(sp.getString("uid", "0"));//消息 未读数量
        getUnReadMsgCount(UserUtil.getUid(ShoppingApplication.application));//消息 未读数量
        if (MiPushMessageReceiver.miPushMessage != null) {//打开小米推送
            MiPushMessage message = MiPushMessageReceiver.miPushMessage;
@@ -457,7 +501,7 @@
     *
     * @param uid
     */
    private void getUnReadMsgCount(String uid) {
    private void getUnReadMsgCount(Long uid) {
        ShoppingApi.getUnReadMsgCount(this, uid, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
@@ -570,7 +614,7 @@
     * @param entity
     */
    public void onEventMainThread(EventMessageEntity entity) {
        getUnReadMsgCount(sp.getString("uid", "0"));
        getUnReadMsgCount(UserUtil.getUid(ShoppingApplication.application));
        if (messagePush != null) {
            // 这里就会调用我们Fragment中的MessagePush方法
            messagePush.MessagePush(true);//传入消息推送
@@ -727,9 +771,8 @@
     * @param homeMsgListListener
     */
    private void getHomeMsgList(final getHomeMsgListListener homeMsgListListener) {
        String uid = getSharedPreferences("user",
                Context.MODE_PRIVATE).getString("uid", "");
        ShoppingApi.getHomeMsgList(this, uid, mPage + "", new BasicTextHttpResponseHandler() {
        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);
@@ -838,13 +881,12 @@
            SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
            if (MobileUtil.getDeviceBrand().equalsIgnoreCase("HUAWEI")
                    || MobileUtil.getDeviceBrand().equalsIgnoreCase("HONOR")) {
                String uid = sp.getString("uid", "0");
                Log.e("eee", "HONOR: ");
                //防止多次请求
                if (System.currentTimeMillis() - lastBindHWTime > 1000 * 5) {//5s后再请求
                    lastBindHWTime = System.currentTimeMillis();
                    Log.e("eee", "上传token");
                    ShoppingApi.bindHMPush(MainActivity.this, token, uid, null);
                    ShoppingApi.bindHMPush(MainActivity.this, token, UserUtil.getUid(ShoppingApplication.application), null);
                }
            }
        }