From 399ac289f80b7a40aa4210341db6b447cacdcf14 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 09 八月 2022 17:42:33 +0800 Subject: [PATCH] 广告升级,隐私政策整改 --- app/src/main/java/com/tejia/lijin/app/ui/main/MainActivity.java | 227 ++++++++++++++++++++++++-------------------------------- 1 files changed, 97 insertions(+), 130 deletions(-) diff --git a/app/src/main/java/com/tejia/lijin/app/ui/main/MainActivity.java b/app/src/main/java/com/tejia/lijin/app/ui/main/MainActivity.java index 7167b5a..07ca102 100644 --- a/app/src/main/java/com/tejia/lijin/app/ui/main/MainActivity.java +++ b/app/src/main/java/com/tejia/lijin/app/ui/main/MainActivity.java @@ -11,12 +11,6 @@ import android.graphics.Color; import android.os.Build; import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; - -import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; @@ -27,24 +21,11 @@ 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.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.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; -import com.wpc.library.okhttp.OkHttpUtils; -import com.wpc.library.util.FragmentSwitchHelper; -import com.wpc.library.util.MobileUtil; -import com.wpc.library.util.NetUtils; -import com.wpc.library.util.common.StringUtils; -import com.xiaomi.mipush.sdk.MiPushMessage; +import com.heytap.msp.push.HeytapPushManager; import com.tejia.lijin.app.BasicTextHttpResponseHandler; import com.tejia.lijin.app.BuXinConstant; import com.tejia.lijin.app.R; @@ -55,14 +36,12 @@ 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.HWPushMessageReceiver; import com.tejia.lijin.app.receiver.MiPushMessageReceiver; -import com.tejia.lijin.app.service.OPPOPushService; -import com.tejia.lijin.app.service.VIVOPushService; -import com.tejia.lijin.app.ui.BrandRebate.BrandFragment; 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; @@ -73,8 +52,20 @@ 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; @@ -85,17 +76,17 @@ 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; - -import static com.tejia.lijin.app.receiver.HWPushMessageReceiver.ACTION_TOKEN; -import static com.tejia.lijin.app.receiver.HWPushMessageReceiver.ACTION_UPDATEUI; /** * 涓婚〉 */ public class MainActivity extends FragmentActivity - implements HWPushMessageReceiver.IPushCallback, DragFloatActionInterface { + implements DragFloatActionInterface { private RadioGroup rg_nav; private View v_no_login; @@ -103,7 +94,8 @@ private SharedPreferences spkefu; - private ImageView img, tv_msg_num2; + private ImageView img; + private TextView tv_msg_count; private DragFloatActionButton acbutton; String tag1 = "systemclient/getsystemclientparams"; @@ -168,7 +160,10 @@ 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 ); + | 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; @@ -177,18 +172,15 @@ 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")); + findViewById(R.id.v_status_bar).setBackground(HomeUIUtil.getHomeTopBg(getApplicationContext())); } else { findViewById(R.id.v_status_bar).setVisibility(View.GONE); } - - - EventBus.getDefault().register(this); @@ -233,12 +225,12 @@ getSystemParams(); v_no_login = findViewById(R.id.v_no_login); acbutton = findViewById(R.id.actionButton); - tv_msg_num2 = findViewById(R.id.tv_msg_num2);//鎴戠殑绾㈢偣 + tv_msg_count = findViewById(R.id.tv_msg_count);//娑堟伅鏁伴噺 acbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //鐧婚檰 - if (getSharedPreferences("user", MODE_PRIVATE).getBoolean("isLogin", false)) { + if (UserUtil.isLogin(getApplicationContext())) { LoginTaobao.getLoginTaobao(MainActivity.this, new LonginTaobaoCallback() { @Override public void onSuccess() { @@ -259,12 +251,6 @@ spkefu = getSharedPreferences("kefurecord", Context.MODE_PRIVATE);//鏄惁鎵撳紑杩囧鏈� 璁板綍 - if (MobileUtil.getDeviceBrand().equalsIgnoreCase("HUAWEI") - || MobileUtil.getDeviceBrand().equalsIgnoreCase("HONOR")) { - HWPushMessageReceiver.registerPushCallback(this);//鎺ㄩ�侀泦鎴愬埌ToolUtil閲岄潰浜� - getToken(); - } - //鑾峰彇 鍙栨秷鎮诞鎺т欢鐨勫楂� ViewTreeObserver vto2 = img.getViewTreeObserver(); vto2.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @@ -282,9 +268,32 @@ choiceTab(fromTab, fromSubTab); } else ((RadioButton) findViewById(R.id.rb_nav_recommend)).setChecked(true); - registeredOPPOId();//涓婁紶OPPO_RegId -// onPush_OFF_NO();//妫�娴嬫槸鍚︽墦寮�鎺ㄩ�� - registeredVIVOId();//涓婁紶VIVO_RegId + + //娉ㄥ唽鎺ㄩ�� + 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) { @@ -313,59 +322,20 @@ } } - /***娉ㄥ唽VIVO_ID**/ - private void registeredVIVOId() { - if (PushClient.getInstance(img.getContext()).isSupport()) { - if (NetUtils.isNetConnected(img.getContext())) { - ToolUtil.registeredVIVORegId(img.getContext()); - } else { - startService(new Intent(img.getContext(), VIVOPushService.class)); - } - } - } - - /** - * 娉ㄥ唽oppoid - */ - private void registeredOPPOId() { - if (PushManager.isSupportPush(getApplicationContext())) { - if (NetUtils.isNetConnected(getApplicationContext())) { - ToolUtil.registeredOPPOId(getApplicationContext()); - } else { - startService(new Intent(getApplicationContext(), OPPOPushService.class)); - } - } - } - - /* - 鍗庝负鎺ㄩ�佽幏鍙杢oken - */ - private void getToken() { - Log.e("mResult", "get token: begin"); - HMSAgent.Push.getToken(new GetTokenHandler() { - @Override - public void onResult(int rst) { - Log.e("mResult", "get token end: " + rst); - } - }); - } - SharedPreferences sp; /** * 绯荤粺琛ュ厖鍙傛暟璇锋眰 */ 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")) { JSONArray array = jsonObject.optJSONObject("data").optJSONArray("systemClientParamsList"); SystemParamsUtil.saveParams(getApplicationContext(), array); boolean input = sp.getBoolean("isFirstInput", true); - boolean isLogin = sp.getBoolean("isLogin", false); + boolean isLogin = UserUtil.isLogin(getApplicationContext()); //鏂颁汉濂界ぜ1鍏冪孩鍖� if (input && !isLogin && sp.getString("newuser", "1").equalsIgnoreCase("0")) { isFirstInput(); @@ -375,7 +345,7 @@ textVideo.isRecord(jsonObject); //鏈嶅姟鍣ㄨ鏄剧ず 璐墿杞�&&鏈湴涔熻鏄剧ず if (textVideo.getCart_float().equals("1") && textVideo.getLocalCart_float() != 1 - && getSharedPreferences("user", MODE_PRIVATE).getBoolean("isLogin", false)) { + && UserUtil.isLogin(getApplicationContext())) { acbutton.setVisibility(View.VISIBLE); } else {//闅愯棌璐墿杞� acbutton.setVisibility(View.GONE); @@ -410,9 +380,9 @@ BuXinConstant.GO_SCAN = false; ((RadioButton) findViewById(R.id.rb_nav_recommend)).setChecked(true); } - boolean isLogin = sp.getBoolean("isLogin", false); + boolean isLogin = UserUtil.isLogin(getApplicationContext()); 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; @@ -438,7 +408,7 @@ RecordImageTextVideo textVideo = new RecordImageTextVideo(MainActivity.this); //鏈嶅姟鍣ㄨ鏄剧ず 璐墿杞�&&鏈湴涔熻鏄剧ず涓嶄负1 if (textVideo.getCart_float().equals("1") && textVideo.getLocalCart_float() != 1 && - getSharedPreferences("user", MODE_PRIVATE).getBoolean("isLogin", false)) { + UserUtil.isLogin(getApplicationContext())) { acbutton.setVisibility(View.VISIBLE); //鐐瑰嚮杩� 鍐嶆樉绀猴紙璁╂寜閽浣嶏級 if (textVideo.getLocalCart_float() == 2) { @@ -452,6 +422,7 @@ acbutton.setVisibility(View.GONE); } } + PushOpenClickActivity.resumeJumpActivity(this); } private void getRecommendInfoFromClipboard() { @@ -491,7 +462,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 { @@ -501,11 +472,15 @@ } else { totalCount = 0; } - totalCount = 0; } else { totalCount = 0; - tv_msg_num2.setVisibility(View.INVISIBLE);//闅愯棌鎴戠殑绾㈢偣 } + + tv_msg_count.setVisibility(totalCount > 0 ? View.VISIBLE : View.INVISIBLE); + if (totalCount > 0) { + tv_msg_count.setText(totalCount >= 100 ? "99+" : (totalCount + "")); + } + setUnReadMsgCount(jsonObject); getgetHomeMsgList();//鑾峰彇鏈娑堟伅鏉℃暟 } @@ -533,7 +508,7 @@ } } //灞曠ず鎴戠殑 绾㈢偣 - tv_msg_num2.setVisibility(jsonObject.optJSONObject("data").optInt("mineCount") > 0 ? View.VISIBLE : View.INVISIBLE); +// int msgCount = jsonObject.optJSONObject("data").optInt("mineCount"); } private void isFirstInput() { @@ -557,8 +532,6 @@ @Override protected void onPause() { super.onPause(); - MobclickAgent.onPageEnd("涓婚〉"); - MobclickAgent.onPause(this); //娉ㄩ攢缇庢唇瀹㈡湇骞挎挱 } @@ -604,7 +577,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);//浼犲叆娑堟伅鎺ㄩ�� @@ -761,9 +734,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); @@ -857,33 +829,6 @@ private static long lastBindHWTime = 0; - @Override - public void onReceive(Intent intent) { - Log.e("eee", "onReceive: "); - if (intent != null) { - String token = ""; - String action = intent.getAction(); - Bundle b = intent.getExtras(); - if (b != null && ACTION_TOKEN.equals(action)) { - token = b.getString(ACTION_TOKEN); - } else if (b != null && ACTION_UPDATEUI.equals(action)) { - } - Log.e("eee", "onReceive: token" + token); - 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); - } - } - } - } - /** * 寮�鍚垨鍏抽棴鎺ㄩ�� */ @@ -936,4 +881,26 @@ } } } + + @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; + } + + } } -- Gitblit v1.8.0