package com.danding.yang800.Presenter;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.danding.yang800.BuildConfig;
import com.danding.yang800.General.HttpCallBack;
import com.danding.yang800.General.Yang800App;
import com.danding.yang800.SetActivity;
import com.danding.yang800.Update.UpdateAppBean;
import com.danding.yang800.Update.UpdateCallback;
import com.danding.yang800.Util.LogUtil;
import com.danding.yang800.Util.ToastUtil;
import com.danding.yang800.Util.VolleyUtil;

import org.json.JSONObject;

import java.util.HashMap;

/**
 * Created by Administrator on 2017/1/12.
 */
public class SetActivityPresenter {
    private SetActivity context;
    SharedPreferences sp;

    public SetActivityPresenter(SetActivity context) {
        sp = context.getSharedPreferences("variable", Context.MODE_PRIVATE);
        this.context = context;
    }


    public void getInfo(final String userId) {
        context.initDialog();
        HashMap<String, String> map = new HashMap<>();
        map.put("userId", userId);
//        new VolleyUtil(context).request(context, "http://" + BuildConfig.HOSTURL + "/xhr/user/setting/toUpdateUserInfo",true, map, new HttpCallBack() {
        new VolleyUtil(context).request(context, "user.setting.toUpdateUserInfo", true, map, new HttpCallBack() {
            @Override
            public void onSuccess(JSONObject json) {
                try {
                    JSONObject jsonObject = json.getJSONObject("result");
                    String mobile = jsonObject.getString("mobile");
                    boolean realNameSet = false;
                    String realname = "";
                    try {
                        realNameSet = jsonObject.getBoolean("realNameSet");
                        realname = jsonObject.getString("realname");
                    } catch (Exception e) {

                    }
                    context.initData(mobile, realNameSet, realname);
                    context.dismissDialog();
                } catch (Exception e) {
                    e.printStackTrace();
                    context.dismissDialog();
                }

            }


            @Override
            public void onerrSuccess() {
                context.dismissDialog();
            }

            @Override
            public void onCatch() {
                context.dismissDialog();
            }

            @Override
            public void onFail() {
                context.dismissDialog();
            }
        });
    }


}
