From 82cc6c94fdc08b1814fbf7195e88cf335eed3e8d Mon Sep 17 00:00:00 2001
From: haijiang <181069201@qq.com>
Date: Wed, 19 Sep 2018 14:00:15 +0800
Subject: [PATCH] 提交

---
 app/src/main/java/com/moral/yunfushao/MainActivity.java |  105 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 98 insertions(+), 7 deletions(-)

diff --git a/app/src/main/java/com/moral/yunfushao/MainActivity.java b/app/src/main/java/com/moral/yunfushao/MainActivity.java
index ccbb4d1..024aa65 100644
--- a/app/src/main/java/com/moral/yunfushao/MainActivity.java
+++ b/app/src/main/java/com/moral/yunfushao/MainActivity.java
@@ -1,10 +1,13 @@
 package com.moral.yunfushao;
 
 import android.Manifest;
+import android.app.AlertDialog;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.ServiceConnection;
+import android.graphics.Color;
+import android.graphics.drawable.ColorDrawable;
 import android.os.AsyncTask;
 import android.os.Build;
 import android.os.Bundle;
@@ -15,6 +18,8 @@
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.Window;
+import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.TabHost;
 import android.widget.TextView;
@@ -24,6 +29,7 @@
 import com.lzy.okgo.cache.CacheMode;
 import com.moral.andbrickslib.utils.FastJsonTools;
 import com.moral.andbrickslib.utils.NetworkUtil;
+import com.moral.andbrickslib.utils.TimeUtil;
 import com.moral.yunfushao.base.BaseActivity;
 import com.moral.yunfushao.ble.BluetoothService;
 import com.moral.yunfushao.common.API;
@@ -33,11 +39,14 @@
 import com.moral.yunfushao.fragment.FragmentShoppongMall;
 import com.moral.yunfushao.httputils.HttpCallBack;
 import com.moral.yunfushao.httputils.HttpUtils;
+import com.moral.yunfushao.imageload.ImageLoader;
 import com.moral.yunfushao.model.EventMessage;
 import com.moral.yunfushao.model.User;
 import com.moral.yunfushao.update.UpdateManager;
 
 import org.greenrobot.eventbus.EventBus;
+import org.json.JSONException;
+import org.json.JSONObject;
 
 import java.util.HashMap;
 import java.util.List;
@@ -118,12 +127,13 @@
 
     @Override
     protected void initListener() {
-
+//        registerBoradcastReceiver();
+//        bleHeart();
     }
 
     @Override
     protected void initData() {
-//        prepare();
+        prepare();
         if(MainApp.theApp.bleManager!=null){
             if(MainApp.theApp.bleManager.isSupportBle()){
                 MainApp.theApp.bleManager.enableBluetooth();
@@ -133,6 +143,7 @@
         }else{
             mToatUtils.showSingletonToast("���������������������������������BLE���");
         }
+        getAd();
     }
 
     @Override
@@ -208,7 +219,7 @@
         protected String doInBackground(String... params) {
             Looper.prepare();
             // ������������������
-            manager.checkUpdate();
+            manager.checkUpdateJson();
             Looper.loop();
             return null;
         }
@@ -243,14 +254,14 @@
                 return;
             String url = API.GET_INFO;
             Map<String, String> params = new HashMap<>();
-            params.put("userID", MainApp.userId);
+            params.put("phone",MainApp.theApp.sharedPreferencesUtil.getLoginInfo().getPhone());
             HttpUtils.doPost(url, params, CacheMode.DEFAULT, false, new HttpCallBack() {
                 @Override
                 public void onSuccess(String res, String msg) {
                     User user = FastJsonTools.getJson(res, User.class);
                     if (user != null) {
                         MainApp.theApp.sharedPreferencesUtil.saveLoginInfo(user);
-//                        MainApp.theApp.userId = user.get_id();
+                        MainApp.theApp.userId = user.get_id();
                     }
                 }
 
@@ -324,12 +335,18 @@
         public void onConnectFail() {
             progressDialog.dismiss();
             mToatUtils.showSingletonToast("������������");
+            EventMessage msg = new EventMessage();
+            msg.setType(AppConfig.GET_BLE_DISCONNECT);
+            EventBus.getDefault().postSticky(msg);
         }
 
         @Override
         public void onDisConnected() {
             progressDialog.dismiss();
-            mToatUtils.showSingletonToast("������������");
+            mToatUtils.showSingletonToast("���������������������");
+            EventMessage msg = new EventMessage();
+            msg.setType(AppConfig.GET_BLE_DISCONNECT);
+            EventBus.getDefault().postSticky(msg);
         }
 
         @Override
@@ -337,7 +354,81 @@
             progressDialog.dismiss();
             EventMessage msg = new EventMessage();
             msg.setType(AppConfig.GET_BLE_SERVICE);
-            EventBus.getDefault().post(msg);
+            EventBus.getDefault().postSticky(msg);
         }
     };
+
+    private AlertDialog adDialog;
+    private View adView;
+    private TextView tv_content,tv_name;
+    private ImageView iv_logo;
+    private Button bt_cancel,bt_ok;
+    private void showAd(String content,String logo,String name){
+        adView = LayoutInflater.from(this).inflate(R.layout.dialog_ad_layout,null);
+        tv_content = (TextView) adView.findViewById(R.id.tv_content);
+        tv_name = (TextView) adView.findViewById(R.id.tv_name);
+        bt_cancel = (Button) adView.findViewById(R.id.bt_cancel);
+        bt_ok = (Button) adView.findViewById(R.id.bt_ok);
+        iv_logo = (ImageView) adView.findViewById(R.id.iv_logo);
+        tv_content.setText(content);
+        tv_name.setText(name);
+        ImageLoader.setCircleImageView(this,logo,iv_logo,R.mipmap.circle);
+        bt_cancel.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                adDialog.dismiss();
+            }
+        });
+        adDialog = new AlertDialog.Builder(this).setView(adView).create();
+        Window window=adDialog.getWindow();
+        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
+        adDialog.show();
+    }
+
+
+    private void getAd(){
+        HttpUtils.doPost(API.GETAD, null, CacheMode.DEFAULT, false, new HttpCallBack() {
+            @Override
+            public void onSuccess(String res, String msg) {
+                if(TextUtils.isEmpty(res)){
+                    return;
+                }
+                try {
+                    JSONObject json = new JSONObject(res);
+                    String time  = MainApp.theApp.sharedPreferencesUtil.getShowAd();
+                    if(TextUtils.isEmpty(time)){
+                        showAd(json.optString("content"),json.optString("logo"),json.optString("name"));
+                        MainApp.theApp.sharedPreferencesUtil.saveShowAd(TimeUtil.getCurrentDate("yyyy-MM-dd"));
+                    }else{
+                        if(time.equals(TimeUtil.getCurrentDate("yyyy-MM-dd"))){
+                            return;
+                        }else{
+                            showAd(json.optString("content"),json.optString("logo"),json.optString("name"));
+                            MainApp.theApp.sharedPreferencesUtil.saveShowAd(TimeUtil.getCurrentDate("yyyy-MM-dd"));
+                        }
+                    }
+                } catch (JSONException e) {
+                    e.printStackTrace();
+                }
+
+            }
+
+            @Override
+            public void showLoadingDialog() {
+
+            }
+
+            @Override
+            public void onFail(int errno, String s) {
+
+            }
+        });
+    }
+
+    public void resetBLECallBack(){
+        if(mBluetoothService!=null){
+            mBluetoothService.setScanCallback(callback);
+        }
+    }
+
 }

--
Gitblit v1.8.0