package com.example.lin_sir_one.tripbuyer.ui.activity;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.os.Message;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVFile;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.SaveCallback;
import com.avos.avoscloud.im.v2.AVIMClient;
import com.avos.avoscloud.im.v2.AVIMException;
import com.avos.avoscloud.im.v2.callback.AVIMClientCallback;
import com.example.lin_sir_one.tripbuyer.R;
import com.example.lin_sir_one.tripbuyer.event.FirstEvent;
import com.example.lin_sir_one.tripbuyer.leanchat.MainActivity;
import com.example.lin_sir_one.tripbuyer.leancloudchatkit.LCChatKit;
import com.example.lin_sir_one.tripbuyer.model.Obj;
import com.example.lin_sir_one.tripbuyer.model.UserInfoModel;
import com.example.lin_sir_one.tripbuyer.network.A;
import com.example.lin_sir_one.tripbuyer.network.HttpResultListener;
import com.example.lin_sir_one.tripbuyer.persistence.Shared;
import com.example.lin_sir_one.tripbuyer.ui.adapter.HomeFragmentAdapter;
import com.example.lin_sir_one.tripbuyer.utils.FileUtil;
import com.example.lin_sir_one.tripbuyer.utils.ImageUtil;
import com.example.lin_sir_one.tripbuyer.utils.MD5;
import com.socks.library.KLog;
import java.io.File;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;
/**
* Created by lin_sir on 2016/7/1.旅行买手主界面,
*/
public class HomeActivity extends AppCompatActivity {
/**
* HomeActivity里面的元素,包括侧滑中的元素
*/
@BindView(R.id.draw_layout)
DrawerLayout draw_layout; //drawLayout
@BindView(R.id.tabLayout_home_activity)
TabLayout tablayout; //tabLayout
@BindView(R.id.iv_user_info_home_activity)
ImageView userInfo; //用户头像
@BindView(R.id.user_name_home_activity)
TextView username; //用户姓名
@BindView(R.id.pager_school)
ViewPager viewPager; //viewPager
private HomeFragmentAdapter mAdapter; //适配器
private Long exitTime = (long) 0;
Message m = null;
String password = "";
/**
* 输入手机号的对话框
*/
private Dialog inputTelDialog; //输入手机号的对话框
private EditText get_pwd; //获取输入的手机号
private ImageView iv_hint; //输入密码下面的那条线
private EditText get_tel_login; //获得到输入的手机号
private ImageView dismiss_login; //关闭这个对话框
private TextView next_login; //下一步按钮
private TextView tv_error_login; //显示输入的手机号有误
private String _tel; //用户手机号
private String _pwd; //用户手机号
private int chose; //选择登录的方式
/**
* 获取验证码对话框
*/
private Dialog getCodeDialog; //获取验证码的对话框
private TextView tvCount; //倒计时的显示
private TimeCount timeCount; //倒计时的实现
private EditText e1; //验证码第一位
private EditText e2; //验证码第二位
private EditText e3; //验证码第三位
private EditText e4; //验证码第四位
private EditText e5; //验证码第五位
private EditText e6; //验证码第六位
private ImageView back_getCode_dialog; //返回按钮
private ImageView dismiss_getCode_dialog; //关闭按钮
private TextView showTel; //显示手机号
private String tel_all; //六位的验证码
/**
* 设置密码对话框
*/
private Dialog setPasswordDialog; //设置密码的对话框
private EditText get_password; //获取设置完的密码
private Button finish; //结束整个注册逻辑
private ImageView dissmissSetPwd; //关闭设置密码的界面
/**
* 所有网络请求的回调接口
*/
private HttpResultListener<Boolean> listener_getCode; //获取验证码之后的回调接口
private HttpResultListener<Boolean> listener_login; //登录之后的回调接口;
private HttpResultListener<Boolean> listener_register; //注册之后回调的接口;
private static final String IMAGE_NAME = "user_avatar.jpg";
private static final int GALLERY_REQUEST = 102;
private static final int GALLERY_KITKAT_REQUEST = 103;
private static final int CAMERA_REQUEST = 104;
private static final int RESULT = 105;
private static final int RESULT_CANCELED = 0;
private Bitmap avatarBmp;
private File avatarFile;//存放拍照选择的头像文件
private AVFile avatar;
private String avatar_file_name = "user_avatar.jpg";
private AVUser currentUser;
private ProgressDialog pdWait;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
initListeners();
ButterKnife.bind(this);
initviews();
initUser();
EventBus.getDefault().register(this);
if (Shared.getUserInfo() != null)
messageLogin();
//Shared.saveCookie("JSESSIONID=BC167CAE0D37C231FD75CB3CC030E6FF");
Log.i("lin", "----lin----> + getCookie " + Shared.getCookie());
//KLog.i("----ooo----> uid"+ Shared.getUserInfo().getUid());
}
private void initListeners() {
/**
*输入手机号,这个时候会进行判断,如果这个手机号没在手机中出现过,就会收到验证码
*如果这个手机好在手机中出现过,就会弹出输入密码的框框
*/
listener_getCode = new HttpResultListener<Boolean>() {
@Override
public void onSuccess(Boolean aBoolean) {
if (aBoolean) {
Toast.makeText(HomeActivity.this, "验证码已发送到您的手机请注意查收", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(HomeActivity.this, "验证码获取失败", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onError(Throwable e) {
Log.i("lin", "-